Overview
When building an Automation, you may choose the "Run a script" action. When an automation containing a "Run a script" action 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 the script in the background of the base. This differs from the scripting block which runs a script in the foreground. For scripts that you would rather run manually the scripting block is the ideal tool. For scripts that you would like to run automatically, setting up a scripting automation is the best choice.
NOTE
Automations is in active development and more functionality is on the way. If you have any feedback to offer, feel free to share that with us here.
Before you begin
- This action is only available on the Pro and Enterprise plans. It is not available on the Pro Trial, Plus, Free, Creator, or Student plans.
- Scripting action does not support interactive input and output. Unlike scripting block, scripting action does not have the ability to display a form or pop up a message.
- The
input.
oroutput.
APIs from the scripting block are not currently available. Automations scripts have different, simpler input/output APIs. - Scripts need to finish in under 30 seconds
- Scripts can use a maximum of 1 second of CPU time
- CPU time is the time spent actually executing your script. Time spent waiting for API requests etc. does not count towards this limit
- Scripts can use 512mb 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.
Need help gathering your ideas? Consider these options:
- Explore the "Example Script Showcase" in the Airtable Universe
- Visit the Airtable community scripting page
Setup
To get started, create your desired Airtable base. In this example, we are creating a simple script that will add the value of two fields together with the result of the calculation appearing in a third field. The script used in this example looks like this:
let table = base.getTable('Calculation');
let query = await table.selectRecordsAsync();
for (let record of query.records) {
let firstnumber = record.getCellValue('First Number');
let secondnumber = record.getCellValue('Second Number');
let calculation = firstnumber + secondnumber;
await table.updateRecordAsync(record, {
"Addition": calculation
});
}
Values specific to your particular base appear in color. The red value is the name of the table the script is referencing. The blue values reference the various number field names you are looking to add together. Finally, the green value represents the field that is being updated with the result of your calculation.
Open the Automations panel and create an automation. Then, choose a trigger, such as "When a record enters a view". In our example, the view was filtered to only show records that have values in the "First Number" and "Second Number" fields. After proper setup, test your trigger by clicking "Run test".
After testing the trigger successfully, we can move onto 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. After you have written or copy and pasted your code into the console, click the blue test button to make sure your code does not have any errors.
After the script action tests successfully you can proceed with toggling on the automation in the upper right-hand corner of the automations console. Notice, the values are automatically calculated after both the first and second numbers have been entered.
FAQs
How is the Automations scripting action different from scripting block?
Scripting block 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.
Automations scripting action scripts 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 escape hatch for when our other automation actions don’t support something, or for advanced automations 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 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 API – post a tweet on Twitter, or use the Airtable API to make a change in another Airtable base. Unlike scripting block, there is no core origin resources sharing (CORS) limitation.
Can I set up a script to run on a schedule using Automations?
At the moment, there isn’t a built-in way to set up a script that runs on a regular time-based schedule (e.g. every day at 9am). A workaround is to use a time-based filter on a view.