Sep 08, 2021 05:58 AM
I have this script I made a month ago. It worked perfectly fine. Just tried it today and it doesn’t work. The fields that I’m updating with updateRecordAsync do not update. They are just blank.
let newRecord = await main.createRecordAsync(obj)
main.updateRecordAsync(newRecord, {
"ID" : newID,
"Discipline" : {name: record.getCellValueAsString("Discipline")},
"Experience" : {name: record.getCellValueAsString("Experience")},
"Duration" : {name: record.getCellValueAsString("Duration")},
"Activity Type" : {name: record.getCellValueAsString("Activity Type")},
"Content": newCombinedText
})
Like I said, this script did exactly as I wanted to in the past. Did something change with updateRecordAsync?
Sep 10, 2021 11:04 AM
Ok so I can definitely move that createRecords out of the loop, but I’m creating multiple records per one record in this script. So idk how else to do it than put it in a loop?
Sep 10, 2021 11:35 AM
The most efficient way to create/update Airtable records is in chunks of 50 or however many you need below that figure.
Build the records to create/update as per usual but instead of doing the createRecordAsync, push them to a separate array declared inside the same scope.
After you’re done composing the batch, the optimal syntax is as follows:
//assuming your queue is called Cache, and you just finished building it out:
Cache.push(lastRecordToHandle);
while(Cache.length)
await base.getTable(YourTableName)
// use whichever one you need here
//.createRecordsAsync(
.updateRecordsAsync(
Cache.splice(0,50));
Sep 10, 2021 11:41 AM
You should use loop to created some array, or object and then pass it to updaterecordS function in a proper way (use output.inspect(array) to debug. it’s hard at beginning, but then much easier to code at all.
i prefer using ‘array helpers’ instead of for… loops (but sometimes for… is no choise option), and own functions
you may see example in ‘Scripting a Rollup Substitute’ topic
Sep 10, 2021 12:02 PM
. it’s hard at beginning, but then much easier to code at all.
Ain’t that the truth. :slightly_smiling_face: