Airtable automation action: Run a script
  • 09 Sep 2024
  • 6 Minutes to read
  • Dark
    Light
  • PDF

Airtable automation action: Run a script

  • Dark
    Light
  • PDF

Article summary

Plan availability

Paid plans only with varying limitations

Permissions

  • Owners/Creators - Create, delete, duplicate, configure, or rename an automation and edit an automation's description.

  • Editors - View an automation's configuration or copy an automation's URL.

Platform(s)

Web/Browser, Mac app, and Windows app 

Related reading

Creating an automation - Learn how to set up your first automation in Airtable.

Setting up a Run a script automation action

Learn how to build an automation that uses the Run a script action. When an automation containing one of these actions runs successfully, it will allow you to trigger a script based on record changes, a form submission, using the Airtable API, and more.

An automation's scripting action runs a script in the background of the base. This differs from the Scripting extension, which runs a script in the foreground. For scripts that you would rather run manually, the Scripting extension is the ideal tool. For scripts that you would like to run automatically, setting up an automation containing a Run a script action is the best choice.

To illustrate how to use the Run a script action, let's walk through an example scenario. In this example, we will create a simple script that will add the value of two fields together with the result of the calculation appearing in a third field.

Step 1: Add a new automation

To start creating an automation, click on Automations in the upper left corner of an open base.

automations_find_01192023

Step 2: Choose a trigger

Next, choose a trigger, such as the When record matches conditions trigger. In our example, the "Calculate?" field is a checkbox field type. When that checkbox field is checked the automation will be triggered to run.

6498246741911automationsTriggerCondition06022022.jpg

Step 3: Setting up input variables

After testing the trigger successfully, we can move on to setting up the action. Click the blue + Add Action button. Then, click on the Run a script option. This will bring up a window for editing your script's code. We'll start by setting up our input variables.

Input variables let you bring information from triggers and previous actions into your Run a script action. In this example, we're going to bring our "First Number" and "Second Number" fields into the script so that we can calculate their sum.

6499182439575automationsInputVariables06022022.jpg

Note

Give careful consideration to how you name your script variables. As a rule of thumb, variables should be clear, descriptive, and distinct.

After we've named our variables and added them in the Input Variables sidebar, we need to declare those variables in our script. We do this by creating an inputConfig variable with the input.config() object, after which we can declare each of our desired variables in the manner shown below:

// Set up input variables
let inputConfig = input.config();
let firstNumber = inputConfig.firstNumber;
let secondNumber = inputConfig.secondNumber; 

Copy and paste the code above into your script editor before proceeding.

Step 4: Setting up your script

Now we're going to add the code below to the main body of our script.

//Perform the calculation
let calculation = firstNumber + secondNumber;

Copy the code above into the console below the input variables we declared above.

Note

For more information on internal Airtable classes that can be accessed via your script—check out our API reference documentation.

Step 5: Setting up output variables

Next, we're going to set up an output variable. Output variables let us pass data from the Run a script action to any remaining actions in the automation run. In this example, we're going to pass our calculation variable to an Update record action. We do this by using the output.set() method to declare any variables we want to use outside of this Run a script action.

// Set the output variable
output.set('calculationOutput', calculation);`

Copy the code above into the console below the rest of the script above, then click the blue test button to make sure your code does not have any errors.

6503554281751automationsTestRun06022022.gif

Step 6: Add an update record action

Now, we'll add one more action to our automation, an Update record action that updates the "Addition" field of the triggering record with the calculationOutput from our Run a script action.

6503900058519automationUpdateRecord06022022.gif

Step 7: Turn the automation on

Once you've successfully tested the Update record action, you can proceed with toggling on the automation in the upper left corner of the Automations console.

Run a script action limits

  • Scripts need to finish in under 30 seconds

  • API calls timeout at 12 seconds

  • Scripts can use 512 MB of memory

  • Scripts can make 50 fetch requests and 30 selectRecords queries.

  • Scripts can make up to 15 mutations a second. A mutation is creating, updating, or deleting records. Each mutation can change up to 50 records at once.

Inputs and outputs

  • Scripting action does not support interactive input and output. Unlike scripting extension, scripting action does not have the ability to display a form or pop up a message.

  • The input and output APIs from the scripting extension are not currently available.

    • Automations scripts have different, simpler input/output APIs. The input/output APIs in the "Run script" action can not intake user input, but they caninput variables for your script to use, and output data from your script for later steps in your API.

    • The output API can return a maximum of 6MB of data.

Note on automation URLs

Starting on January 25th, 2022, Airtable made a change to URL formatting in Automation triggers and actions. Now, the base ID (appXXXXXXXXXXXXXX) will appear at the start of the URL path. This change coincides with the Understanding Airtable IDs throughout the rest of product. The change in record URL format will occur in these places:

  • The url property of a record output by a trigger/action.

  • The url property of a Table or View model retrieved by the Run Script action.

This may be a breaking change if your automation makes hard assumptions about the format of a URL property (e.g. by deconstructing the returned URL into its component parts or similar). No action should be needed if your automation only uses the URL for navigational purposes. Browser navigation will continue to work for the old-style Airtable URLs via redirects, although these redirects may not be supported indefinitely in the future. If your automation constructs Airtable URLs from scratch, we recommend updating the construction logic to also include the base ID.

FAQs

How is the Automations scripting action different from the Scripting extension?

Scripting extension scripts run in the foreground of the base. They’re triggered directly by a user, who is then able to see any output from the script and add any additional input the script asks for. They’re ideal for automating workflows that require some human involvement.

Scripts from the scripting action run in the background of the base. They’re triggered indirectly and run automatically behind the scenes while the user keeps working. They’re ideal as an extensible tool for when our other automation actions don’t support something, or for advanced automation use-cases.

Will the script run even if my base is not open?

Yes. Once enabled, the script will run when a record enters the view, regardless of whether the base is open. This allows you to schedule when a script runs, or trigger a script based on a form submission or by using the Airtable API to create or edit a record.

What APIs can I access using the Automations scripting action?

You can access any external API or use the Airtable API to make a change in another Airtable base. Unlike the scripting extension, there is no core origin resources sharing (CORS) limitation.

Can I set up a script to run on a schedule using Automations?

Yes, it is possible to set a script to run on a schedule using the "At a scheduled time" trigger. Learn more here.

Is the “Run a script” action available on Team plan trials?

No, the “Run a script” action is not available on a Team plan trial.

My automation is throwing a scripting error, how do I troubleshoot the issue?

You’ll want to use the run history to reveal the “Execution log” to troubleshoot as outlined here.

Need help gathering your ideas? Consider these options:


Was this article helpful?