Sep 16, 2021 10:43 AM
Hello All,
I have the following script that I use to create links between tables based on the “ID,” which is consistent between the two tables. Typically, I run this script manually every few days or so, but I have recently discovered the “Run a Script” automation, which would completely eliminate the need for manually clicking the “Run Script” button. However, the following script throws an error every time I test the automation (which is when a new record in the “Enrollment” table is created, the script is supposed to run). I’ve gathered that this is an issue with certain functions not being recognized in the automation, however I do not know how to fix this. Any help would be greatly appreciated!
//Define the Facilities table and query
var facTbl = base.getTable(“Facilities”);
var facQuery = await facTbl.selectRecordsAsync();
//Define Enrollment table and query
var conTbl = base.getTable(“Enrollment”);
var conQuery = await conTbl.selectRecordsAsync();
// Create an updates array
let updates = ;
//Loop through the records of Facilities
for (let facRecord of facQuery.records) {
let FacTpID = facRecord.getCellValue(“ID”);
let Sources = ;
//Loop through the records of Results table
for (let resRecord of conQuery.records) {
if (resRecord.getCellValue(“ID”) === FacTpID) {
Sources = […Sources,{id: resRecord.id}]
}
}
// Push update into the updates array
updates.push({
id: facRecord.id,
fields: {
‘Enrollment’: […Sources]
}
});
}
// Update records
while (updates.length > 0) {
await facTbl.updateRecordsAsync(updates.slice(0, 50));
updates = updates.slice(50)}
Solved! Go to Solution.
Sep 16, 2021 11:12 AM
Sep 16, 2021 11:12 AM
Sep 16, 2021 12:07 PM
Hi kuovonne,
Thanks for your reply! I saw that the Airtable team just fixed the scripts issue and the automation is now running perfectly. Thank you for your reply!