Add the Table and the (Table) Fields to the Data Model – otherwise using “.addRow()” doesn’t work.
Make sure that the property names used in the JavaScript code “ItemsSortedArray.push({...})” matches with the names of the Field added to the Table, which you’ve just added to the Data Model.
Add the following lines of JavaScript code to the to the Action Step applied Script:
for(var i = 0; i < ItemsSortedArray.length; i++)
record.tables["itemsSorted"].addRow(ItemsSortedArray[i]);
}
But this will unfortunately result in an error by execute the JavaScript code:
The error: Cannot call method “addRow” of undefined
Therefore I am going to suggest to:
Remove the second Repeat Step.
Add the Table and the (Table) Fields to the Data Model – otherwise using “.addRow()” doesn’t work.
Add a Action Step to the first Repeat Step
Add the following JavaScript code to the to the Action Step applied Script: “record.tables.itemsSorted.addRow({}); // Adds an empty row to the table”
Make sure that the property names used in the JavaScript code “ItemsSortedArray.push({...})” matches with the names of the Field added to the Table, which you’ve just added to the Data Model.
Add the following lines of JavaScript code to the Script applied to the Action Step
for(var i = 0; i < ItemsSortedArray.length; i++) {
record.tables["itemsSorted"][i].set(ItemsSortedArray[i]);
}
I can’t tell you why your steps don’t work and I suggest you report this to our Technical support team via our website, but through scripting I accomplished what you want.
Saved it in 2021.2.1 so other users can see the script until 2022.1 is released.
Thanks guys it is working.
Just one more question for the experts.
I need to sort the datalist by first location and then itemnumber
I tried this in the script, but it does not work.
return a.LocationNumber>b.LocationNumber || a.ItemNumber > b.ItemNumber;
and
return a.LocationNumber>b.LocationNumber || a.ItemNumber.localCompare > b.ItemNumber;
I have added a new xml to the datamapper with only two items on same location but with different item numbers.
I want 0882 before 0883 on that location.
Can you also solve that ?[1152325.xml|attachment](upload://bXs60AZaP0hOZSZaZPWhMZOxIBV.xml) (29.2 KB)
I’m looking on this resolution but my scenario is more complex having nested tables. Once the section table sorted, all its table details below should follow. Any idea how I can do it?