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.
Question
Question
new forms designer, table rows based on variable
Replies
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:
- Add a new field to the form and hide it with field rules.
- You can use a formula to populate the number of rows in this table COUNT(Table1.EquipmentID).
- Change the number 51 (two occurrences) to the field ID of this new field
- Use JS to watch for changes to this field
- Grab the values of table 1's Equipment ID column
- 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 } );
This page has a lot of useful information that might help you:
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!
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.
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.
It is not coming from an external data source. It is coming from a table in the same form though.
How are you copying the data between the two tables? Formulas, Javascript, variables from a prior submission?
Formulas
=INDEX(Table.ID1,ROW())