- 19 Jan 2023
- 6 Minutes to read
Airtable automation action: Run a script
- Updated on 19 Jan 2023
- 6 Minutes to read
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.
|Plan availability||Pro and Enterprise plans only with varying limitations|
|Platform(s)||Web/Browser, Mac app, and Windows app|
Setting up the "Run a script" action
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.
To start creating an automation, click on Automations in the upper left corner of an open base.
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.
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.
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.
Now we're going to add the code below to the main body of our script.
//Perform the calculation let calculation = firstNumber + secondNumber;
For more information on internal Airtable classes that can be accessed via your script—check out our API reference documentation.
Copy the code above into the console below the input variables we declared above.
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.
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.
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.
outputAPIs 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.
outputAPI can return a maximum of 6MB of data.
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.
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.
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.
You can access any API – post a tweet on Twitter, 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.
Yes, it is possible to set a script to run on a schedule using the "At a scheduled time" trigger. Learn more here.
Need help gathering your ideas? Consider these options:
- Explore the "Example Script Showcase " in the Airtable Universe
- Visit the Airtable community scripting page
- Check out our Scripting documentation for examples of Scripts