Skip to main content

Script to help reset running balance counter to actual amount counted

  • November 10, 2024
  • 2 replies
  • 40 views

Forum|alt.badge.img+2

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

TheTimeSavingCo
Forum|alt.badge.img+31

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?


Forum|alt.badge.img+2
  • Author
  • New Participant
  • November 11, 2024

How?