← All blog posts

How to run a script for an array of records in Airtable Scripts

Learn how to run a script for an array of records in Airtable records. This method can be used to bulk update records.

October 13, 2022

A very common automation use case that needs to be solved for is running workflows for many records rather than just one. Tools like Nobull from Finsweet, Parabola or Make.com are very good at allowing to do this, but did you know with only a few lines of codes you will be able to do the same in Airtable Scripts.

‍

Importing your table

The first thing we want to do writing our script is to make sure we are importing an array of records rather than just importing a single record. We can do this using the "query.records" function after we define our base and table.

‍

Running a script for every record in our array

Once we have successfully queried our set of records in our table or view, we will now be able to use the for function to run a script or function for each record within our array. Once we have added our script within the for function, Airtable scripts will run for through each and run the script that we specified.

After your run your script, you should see a list of properties returned

‍

How to use the "for" function

The "for" function can be used for a lot of different things, but properly the most common use case is to bulk create or bulk update records. If for example, you have added a new fields to your Webflow CMS and you want to update all of your records with a value that sits inside of Airtable, then you will be able to do just that with the for function.

Use the code


//import the table
let table = base.getTable("Properties");
let query = await table.selectRecordsAsync();
let records = query.records;

console.log(records);

//run a script for each record in a table
for (let record of records){
    //if trigger automation field is "approved" run the script
    if (record.getCellValue("Trigger Automation").name === "Approved" || (record.getCellValue("SQFT")>2000)){
            output.text(`${record.name} is included in our properties table`)
    }
}
Copy

Dive Deeper with the Stripe Payment Links scripting series

Learn how to use Airtable Scripts to generate Stripe Payment Links for your online store and more!

Learn more →
Subscribe to the newsletter!

Get notified when I publish my next video or blog

😘 Got it!
Oops! Something went wrong while submitting the form.
ChatGPT 🀝 No-Code - How to create and schedule social posts with AI

ChatGPT 🀝 No-Code - How to create and schedule social posts with AI

As part of the booknotes.ai series, I will show you how to build a workflow for creating and scheduling social media marketing posts. For this example, I will be using Instagram, but you can set up this workflow for whatever other social media platform you want to use, like Twitter, LinkedIn, etc. In the first part of this series, I showed you how I created booknotes.ai, a book recommendation service created with AI.

How to build a book recommendation site with AI

How to build a book recommendation site with AI

I will show you how I used ChatGPT by OpenAI to create a book recommendation site in Webflow. I will take you behind the scenes and show you what tools I used, what processes I followed and what my thoughts are on using AI to generate these types of sites.

How to use Whalesync for two-way syncing between Airtable and Webflow

How to use Whalesync for two-way syncing between Airtable and Webflow

I checked out Whalesync, a tool for two-way syncing between tools like Airtable, Webflow, Bubble, Noton and more, to see how useful two-syncing is.

How to build a dynamic testimonial section with the Webflow CMS

How to build a dynamic testimonial section with the Webflow CMS

Learn how to create a dynamic section in the Webflow CMS for product reviews, testimonials, and more. Watch the step-by-step process of designing, building, and automating a brand-new section on my profile page.

How to allow clients to manage your no-code builds with Airtable Interfaces

How to allow clients to manage your no-code builds with Airtable Interfaces

I help a lot of people set up bases for their marketplaces or sometimes even for clients, and a question that keeps coming up is how can you allow your clients to safely manage their Airtable base without overwhelming them with the complex setup?

How to instantly trigger Airtable workflows in make.com using webhooks

How to instantly trigger Airtable workflows in make.com using webhooks

If you want to run a make.com workflow that triggers when something happens in Airtable, you typically have to wait for 5 - 15 minutes depending on how you set your schedule - unless you use a webhook fired from inside Airtable Automations.