Gallery
Kuovonne's Guide to Scripting in Airtable
Share
Explore
Automation Scripts

Converting a script to run as an automation

Your donations tell Kuovonne that you value her content and want her to continue publishing.
Say you found the perfect script for your needs, except that it runs in Scripting Extension, and you want to run it as an automation? How can you get that script to run as an automation? This article explores some of the concepts involved for people who are new to code.

When converting isn’t possible

In some situations, a script cannot be converted to run as an automation:
The script needs user input that cannot be hard-coded in advance or omitted.
The script inputs a file from the local computer with input.fileAsync.
In other situations, a script might need significant changes that are beyond the scope of this article. Note that these situations might not show up until a script is run in a production environment with many records. See for more details.

Converting script settings

Some (but not all scripts) contain script settings. If a script has a section that looks like this, it uses script settings. This entire section needs to be reworked to hard-code your table and field names, and any other options.
let config = input.config({
title: 'Your script with settings',
description: 'A script that uses settings',
items: [
input.config.table('selectedTable', {
label: 'Table to use',
description: 'Pick any table in this base!',
}),
input.config.field('selectedField', {
label: 'Field inside the above table',
parentTable: 'selectedTable',
}),
input.config.text('companyName', {
label: 'Company name',
}),
input.config.number('maxItemsPerOrder', {
label: 'Maximum number of items per order',
}),
]
});
let selectedField = config.selectedField;
let companyName = config.companyName;
let maxItemsPerOrder = config.maxItemsPerOrder;
The automation script version would would look like the following. Replace the names of the table and field with the names that match your base. Replace the text and number with the actual text and numbers you want to use.
const selectedTable = based.getTable("Table Name");
const selectedField = selectedTable.getField("Field Name");
const companyName = "My Company";
const maxItemsPerOrder = 10;

Getting the triggering record

If your script uses input.recordAsync to get a triggering record from the user, you need a completely different method of getting the triggering record and its field values.
For example, convert
let record = await input.recordAsync('Pick a record', table);
to
let inputConfig = input.config();
let recordId = inputConfig.recordId;
let record = await table.selectRecordAsync(recordId, {fields: table.fields});
You will also need to create the input variable recordId in the left panel of the scripting editor and set it to a valid record ID.
image.png

Removing user input

If your script uses input to get input from the user, such as input.textAsync, or input.buttonsAsync, you will need to hard-code those values.
For example, convert
let catOrDog = await input.buttonsAsync('Cats or dogs?', ['Cats!', 'Dogs!']);
to
let catOrDog = 'Cats!';

Removing Output

If your script uses output to show information on the screen, such as output.text, output.markdown, or output.table, you will need to either delete those lines of code or convert them to use console.log. If your script uses output.clear(), delete it.
For example, convert
output.text('Hello, world!');
to
console.log('Hello, world!');
The content in this guide is free, but creating it takes time and money. If you like this content, .

Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.