I am using the following script for when a new record is added that will provide a running total.
// Hard-coded table and view names
let tableName = 'Invoices';
let viewName = 'Grid view';
let table = base.getTable(tableName);
let view = table.getView(viewName);
let result = await view.selectRecordsAsync({ fields: ['Amount'] });
let runningTotal = 0;
for (let record of result.records) {
// Hard-coded field names
let amount = record.getCellValue('Amount');
runningTotal += amount;
// Hard-coded field name for updating the record
await table.updateRecordAsync(record, {
'Running Total': runningTotal,
});
}
Runs well and little too well. 😂
When I add a record it runs the script before I'm able to add the amount and a new blank must be added for the correct calculation to appear. Is there some sort of delay that I could add or am I taking the wrong approach?