Mar 05, 2020 04:49 PM
Here is a script that will count records per table and output the result as a little CSV output.
It is a little quick and dirty and will take ‘some time’ to run if you have large record counts.
Hope it is useful to someone.
let tableCount = base.tables.length;
let totalRecords = 0;
for(let i = tableCount - 1; i >= 0; i--){
let name = base.tables[i].name;
let table = base.getTable(name);
let result = await table.selectRecordsAsync();
totalRecords += result.records.length;
output.text(name + ' , ' + result.records.length);
}
output.text('Total Records in ' + base.name + ', ' + totalRecords);
Mar 06, 2020 09:52 AM
wooof!
I had no idea all that data for each field had to be loaded in the background - thanks for pointing that out, @kuovonne!
I thought selectRecordsAsync()
was just queueing up record identities for batch operations, and providing easy access to the fields/contents (since I assumed all the field data was already “loaded” into the browser by virtue of being in the table already).
Mar 06, 2020 09:55 AM
Me too! This is a deep insight worth knowing about.
Oct 19, 2020 02:34 PM
This just sped up my script dramatically!! Thank you for insight!
Jan 30, 2022 09:10 AM
What does input
represent here? Is that a variable that was set elsewhere?
Jan 30, 2022 09:27 AM
The input
object is provided by the scripting environment by the Scripting app, just like the base
object and a handful of other objects. They are covered in the documentation.
Note that if you want to count the number of records in an automation script, you probably will not use the input
object. Instead you will need to hardcode the name of the table.
May 08, 2023 05:07 PM
Thanks so much for this, it's very useful!