Help

Re: Script to count records in tables and total in base

2234 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Nigel_James
5 - Automation Enthusiast
5 - Automation Enthusiast

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);
25 Replies 25

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).

Me too! This is a deep insight worth knowing about.

This just sped up my script dramatically!! Thank you for insight!

What does input represent here? Is that a variable that was set elsewhere?

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.

lizfitz
5 - Automation Enthusiast
5 - Automation Enthusiast

Thanks so much for this, it's very useful!