You are viewing limited content. For full access, please sign in.

Question

Question

new forms designer, table rows based on variable

asked on October 2, 2024

I have a form that has the user put in all the equipment ID's in one table, then those IDs populate the first column is a subsequent table, but the subsequent table only shows the first row. When the user adds the second row, it populates correctly with next equipment ID from table one, but I want the table to automatically show all the rows in table one whether there is one equipment ID or 30 equipment IDs.

0 0

Replies

replied on October 2, 2024

If table 1 is not populated by a lookup and you want table 2 to have the same amount of rows, you will have to use JavaScript. The basic procedure is:

  1. Add a new field to the form and hide it with field rules.
    1. You can use a formula to populate the number of rows in this table COUNT(Table1.EquipmentID). 
    2. Change the number 51 (two occurrences) to the field ID of this new field
  2. Use JS to watch for changes to this field
  3. Grab the values of table 1's Equipment ID column
  4. Set the values of table 2's Equipment ID column

The only issue is if they begin work on table 2 then edit table 1 they will have their IDs overwritten in table 2. Let me know if this is an issue and we may be able to work around it.

 

const updateTableRows = async (tableFieldId, rowCount) => {
  const currentTableFieldValues = LFForm.getFieldValues(tableFieldId);
  const curRowCount = currentTableFieldValues.length;

  if (curRowCount < rowCount) {
    await LFForm.addRow(tableFieldId, rowCount - curRowCount);
  } else if (curRowCount > rowCount) {
    await LFForm.deleteRow(
      tableFieldId,
      ...Array.from(Array(curRowCount - rowCount)).map(
        (_, i) => curRowCount - i - 1
      )
    );
  }
};

let lastFieldValue = null;

LFForm.onFieldChange(
  async () => {
    const fieldValues = LFForm.getFieldValues({ fieldId: 51 });

    // Check if the field value has changed since the last time a row was added
    if (fieldValues[0] !== lastFieldValue) {
      // Update the table rows with the new row count
      await updateTableRows({ variableName: 'tbl_perDiem' }, fieldValues);
      lastFieldValue = fieldValues; // Update the last field value
    }
  },
  { fieldId: 51 }
);

 

2 0
replied on October 2, 2024 Show version history

This page has a lot of useful information that might help you:

https://doc.laserfiche.com/laserfiche.documentation/11/administration/en-us/Subsystems/Forms/Content/Forms/Form-Fields/Table.htm

You'll want to select "Append rows to the rows populated by a data source or variable", then set the min and max to 0 if you only want the populated rows, or add whatever range works for you if you want people to be able to add additional rows and fill in the information themselves.

Hope this helps!

0 0
replied on October 2, 2024

This doesn't help.  So in table one, there may be 2 rows, there may be 10 rows, there may be 25 rows.

In table 2, I want column 1 to match column 1 in table 1 (which I can do, but the user has to click add for each row to be added).  I'd like it to just prefill and show the same number of rows in table 2 as in table 1.

0 0
replied on October 2, 2024

Sorry, for clarity - You would use the above settings for table 2. I've used this for a number of tables populated by a varying length lookup without any issues.

0 0
replied on October 2, 2024

It is not coming from an external data source. It is coming from a table in the same form though.

 

0 0
replied on October 2, 2024

How are you copying the data between the two tables?  Formulas, Javascript, variables from a prior submission?

0 0
replied on October 10, 2024

Formulas  

=INDEX(Table.ID1,ROW())

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.