Feb 17, 2022 10:52 AM
Hi,
I’m new to Airtable scripting and figuring this out as I go along. What I’m trying to do is to get a script to count the number of non-empty records for a specific field in one of my tables. This is because this field does have some blank values for some records and I don’t want to simply count all the records in the table.
let query = await myTable.selectRecordsAsync({
fields: [myField],
});
let recordCount = query.records.length;
When I use the script above, I get the total number of records in myTable.
How can I add a condition to this so that I’m only getting a count of those records where myField is not empty?
Thanks
Feb 18, 2022 05:33 AM
There are two aspects to doing this
record.getCellValue(field)
for this.There are multiple ways to get the count. Which method to use depends on you coding experience and what you are most comfortable with. Here are just a few common methods.
for
loop to loop through the records, and a sum
variable that gets increments inside the loop if the record has a valuefilter
function that identifies records that meet your condition, then get the length of the filtered arrayreduce
function to reduce the array to a numberPick the method that fits your current level of coding experience. If you are new to coding and want to learn to code, I recommend implementing all three as part of your learning journey.
Feb 18, 2022 05:53 AM
Thanks kuovonne. That makes sense.