Help

Re: Script to help reset running balance counter to actual amount counted

200 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Niyatee_Sharma
4 - Data Explorer
4 - Data Explorer

I have this table set up where I have a running balance of what being added and taken from a cash register. I am running this script for it:

 

// change these names to pick a view:
let table = base.getTable('TIN');
let view = table.getView('ALL');

let result = await view.selectRecordsAsync({fields: ['Gross Added or Subtracted']});
let runningTotal = 0;
for (let record of result.records) {
// change the field names here to adapt this script to your base
runningTotal += record.getCellValue('Gross Added or Subtracted');
await table.updateRecordAsync(record, {
'Running Balance': runningTotal,
});
}
 
BUT, when someone counts the actual amount in the register, I want the running balance field to become equal to the actual count. How to I do this? 
2 Replies 2

Looks like you're re-calculating the totals every time the script is run, is that right?  If so, you could just create a formula field that outputs the Actual Tin Count if that exists, and if not, it'll output the Running Balance?

Niyatee_Sharma
4 - Data Explorer
4 - Data Explorer

How?