Here is a script I am using now. You need to loop through the table to add up values in a certain column. The below code used a test Find Text called @test@. Result gets returned as the total. You need to change c1 to your table name in the line containing “record.tables.c1.length” and your table and the tables field you want to calculate in “record.tables.c1[i].fields.Amount;”
This sort of calculation is readily done in your datamapper as well. In short, inside your loop where you’re creating the detail table in the datamapping, you can also be adding your line total to an invoice total field via an action step.
Attached is a sample of how to do this. In this data there are no totals, so the line total and invoice subtotal both needed to be calculated. You could take this a step further and calculate tax and the final total too.
First, you must create your total field ahead of time. You can see I’ve done this in the main Extraction step by including an empty javascript extraction to create InvoiceSubTotal.
Second, the Action step inside of the loop is used to write the values you’re currently extracting from your data back into your previously defined field using a logic of A = A + B.