Hello!
I am looking for some help with correcting this script (I had Copilot AI help write it) for Airtable. I'd like for the automation to tick a checkbox "Fully Live" in the table "App Status" when a button is pushed in a specific interface.
I'll attached screenshots of the script error, the table we'd like to have updated and the script itself.
Any help would be greatly appreciated!
I am not married to having to use the button in the interface to initiate the automation. I have another table called Monthly RTLs where the button could be added. When I add a button field there, it wants me to add it to a Dashboard and I got confused - that's why the script references that table.
This is the script error.
This is the interface associated to the Monthly RTLs Table.
The field "Fully Live" lives in this table here called App Status. This is where all data for a record is held. My department primarily works off of this view and updates the table Monthly RTLs when a store is completed with all tasks.
// This script updates the "Fully LIVE" checkbox field in the "App Status" table
// when the "FULLY LIVE" button is pushed in the "Monthly RTLs" table.
// Define the base and tables
let base = await Airtable.base.fetch('YOUR_BASE_ID');
let appStatusTable = base.getTable('App Status');
let monthlyRtlsTable = base.getTable('Monthly RTLs');
// Define the button name and checkbox field name
let buttonName = 'FULLY LIVE';
let checkboxFieldName = 'Fully LIVE';
// Define the action to take when the button is pushed
let buttonPushed = async (event) => {
// Get the record that was updated
let record = await monthlyRtlsTable.selectRecordsAsync({
fields: ['Name', checkboxFieldName],
filterByFormula: `{${buttonName}} = '1'`,
maxRecords: 1,
sort: [{field: 'Created Time', direction: 'desc'}]
});
// If there is a record that matches the filter, update the checkbox field in the App Status table
if (record.records.length > 0) {
let appStatusRecord = await appStatusTable.updateRecordAsync(record.records[0].id, {
[checkboxFieldName]: true
});
output.text(`The "${checkboxFieldName}" field in the "App Status" table has been updated to "true".`);
} else {
output.text(`No records in the "Monthly RTLs" table match the filter.`);
}
};
// Listen for the button to be pushed
monthlyRtlsTable.watch(buttonName, buttonPushed);