Jun 06, 2022 08:44 AM
I have an automation that I need to count all records that meet a certain criteria. The number of records that meet this criteria exceeds 100, so the find records tool isn’t useful. There is a scripting block in the automation and I would like to count them there, but I’m not seeing an easy way to do this.
I only need the step to return the count of records that meet the criteria, not the actual records themselves. Has anybody done something similar?
Ideally I could make a view with the criteria filtered and then have the scripting step return the number of records in the view, but I don’t see any documentation for a function to fetch record count within a view in the API docs. Also don’t see a way to use selectRecordsAsync with an offset to capture all records that meet a criteria instead of just the 100 allowed by the function as it currently exists. Any thoughts?
Solved! Go to Solution.
Jun 06, 2022 08:49 AM
Read to the end of the thread to get how to use output.set
so you can use the count in a future automation step.
Jun 06, 2022 08:49 AM
You have the right idea. Loading a query from a view will return an array of records. Like any array in javascript, doing array.length
will give you the total number of items in that array, which in this case would be the count of records in that view.
let table = base.getTable("Table");
let view = table.getView("Criteria");
let query = await view.selectRecordsAsync({fields: []})
let records = query.records
let count = records.length
Jun 06, 2022 08:49 AM
Read to the end of the thread to get how to use output.set
so you can use the count in a future automation step.
Jun 06, 2022 10:30 AM
Thank you! This is perfect.