Hello and welcome to the Community @James_Brace!
You could definitely write a script to do what you have outlined above, but if you do not have experience with JavaScript I think there may be an easier way to get the total sales value onto the table itself.
You could set the sales total on the table itself by associating the records together as described in this support article.
If you would like to continue using your script you can add values within a script by iterating through your records and then using +=
to add them together like so:
let table = base.getTable('Employees');
let view = table.getView('Grid view');
let result = await view.selectRecordsAsync();
let runningTotal = 0;
// iterate through all the records
for (let record of result.records) {
// using += will reassign the value of runningTotal to
// include the 'Amount' value from the record
runningTotal += record.getCellValue('Amount');
await table.updateRecordAsync(record, {
'Running total': runningTotal,
});
}
Let me know if I can help provide any more information, and if this helped answer your question please mark it as the solution :white_check_mark: .