Now you have two arrays: 1/ allProjects.recordIds that will return an array of recordIds in your table and 2/ allProjects.records that is an array of objects containing an id and a name. You can now loop on those two instances (allProjects.recordIds and/or allProjects.records) to retrieve information, compare it, update it etc.
Looping
Now that you have your list of records, to loop on them and “do things” you can use array methods! These are convenient shortcuts in Javascript that let you do a specific action. The ones I’ve found most useful and common are
find,
filter and
map. Here’s how I understand each one:
let newProjects = allProjects.records.filter (project => (condition))
The filter method will loop over each record (using the project variable) and return (insert in newProjects) all records that match a certain condition. It’s useful for finding a subset of records in your table that match certain conditions!
let newProjects = allProjects.records.find (project => (condition))
Find is similar to filter in that it will loop over your records (using the project variable) but instead of returning all records that match a condition, it will only return the first instance. It’s useful for checking if something is true (is there another record with the same email?).
let newProjects = allProjects.records.map (project => (function))
The mecca of methods: map will loop over your records and execute a function. I’ve mainly used it in to create arrays that have the data I need to create/update records.
If you understand how to retrieve data, output data and how to use those three methods, you should be pretty much set to get comfortable writing Airtable scripts!
More scripting?
We’ve got 2 more sessions on live Airtable scripting happening on
AirtableTV. I’d love to keep writing scripts live on
my own channel but I’m wondering if there’s enough interest to make it a recurring session on the stream.
Do you want to learn Airtable scripting? Would you watch more live Airtable scripting? Do you have a script you’re struggling to write and want me to try to write it? If you answered yes to any of these, let me know by replying to this email or reaching out on
twitter. If there’s interest, I’ll add some sessions to the calendar!
Best
Aron