asked on November 12

I would like to copy data from the original table(variable= EquipmentVehicleInventoryOriginal)  and duplicate it across several other tables (variable = EquipmentVehicleInventoryDuplicate_ , EquipmentVehicleInventoryDuplicate_2 , EquipmentVehicleInventoryDuplicate_3 ,  EquipmentVehicleInventoryDuplicate_4 , EquipmentVehicleInventoryDuplicate_5 , EquipmentVehicleInventoryDuplicate_6 , EquipmentVehicleInventoryDuplicate_7) . Here is the code I am currently using, but it is not working as expected. Can anyone help me troubleshoot this?

 

// Define the variable names

const originalTable = '.EquipmentVehicleInventoryOriginal';

const duplicateTables = [

    '.EquipmentVehicleInventoryDuplicate_',

    '.EquipmentVehicleInventoryDuplicate_2',

    '.EquipmentVehicleInventoryDuplicate_3',

    '.EquipmentVehicleInventoryDuplicate_4',

    '.EquipmentVehicleInventoryDuplicate_5',

    '.EquipmentVehicleInventoryDuplicate_6',

    '.EquipmentVehicleInventoryDuplicate_7'

];

 

// Function to duplicate table data

function duplicateTableData(originalTableVar, duplicateTableVars) {

    // Get the original table rows

    const originalRows = LFForm.getValues(originalTableVar);

 

    // Loop through each duplicate table

    duplicateTableVars.forEach(duplicateTableVar => {

        // Clear existing rows in the duplicate table

        LFForm.clearTable(duplicateTableVar);

 

        // Copy each row from the original to the duplicate table

        originalRows.forEach(rowData => {

            const newRowIndex = LFForm.addRow(duplicateTableVar);

           

            // Loop through each field in the row and copy it to the new row

            for (const field in rowData) {

                if (rowData.hasOwnProperty(field)) {

                    // Set the value in the duplicate table's new row

                    LFForm.setFieldValue(`${duplicateTableVar}[${newRowIndex}].${field}`, rowData[field]);

                }

            }

        });

    });

}

 

// Call the function

duplicateTableData(originalTable, duplicateTables);

0 0