Dec 31, 2021 04:11 AM
I’m trying to simply copy text from one column to another. Only about 20% of the records are being copied over. However the console logs each name correctly…
Im using this script, which i’ve edited for my own use from here:
// set the table
let table = base.getTable("Inventory Item Summary");
// get the table records
let itemCode = await table.selectRecordsAsync();
// loop through the records
for (let record of itemCode.records) {
// set variables to the record values
let itemCode = record.getCellValue("Item Code");
// only run on records which have notes
if (itemCode) {
output.text(`Copying notes for record ${record.name}`)
// build the newNotes value from the notes...
let newItemNumber = itemCode
table.updateRecordAsync(record, {
"Item Number": newItemNumber
})
}
}
Any help would be appreciated!
edit: i believe selectRecordsAsync() is deprecated, could this have something to do with it?
edit2: Doesn’t seem to be because of the deprecation, i changed it to:
let itemCode = await table.selectRecordsAsync({fields: ['Item Code']});
and still no change
edit 3:
Ive added an else statement, and it seems itemCode exists, and im not getting any ‘failed’ results
if (itemCode) {
output.text(`Copying notes for record ${record.name}`)
table.updateRecordAsync(record, {
"Item Number": itemCode
})
} else {
output.text('failed')
}
Solved! Go to Solution.
Dec 31, 2021 06:44 AM
Welcome to the Airtable community.
More specifically, you script is updating exactly 15 records. This is because you are updating the records one at a time inside a loop without awaiting the result. Airtable has a rate limit of 15 update requests per second. This rate limit is why addition requests are failing to be processed by Airtable’s servers. You are not seeing the errors because your script ends before Airtable returns with the error.
There are two possible fixes
await
in front of table.updateRecordAsync
Adding the await
keyword is the easier to implement solution. However, learning to update in batches will serve you better in the long run.
Dec 31, 2021 06:44 AM
Welcome to the Airtable community.
More specifically, you script is updating exactly 15 records. This is because you are updating the records one at a time inside a loop without awaiting the result. Airtable has a rate limit of 15 update requests per second. This rate limit is why addition requests are failing to be processed by Airtable’s servers. You are not seeing the errors because your script ends before Airtable returns with the error.
There are two possible fixes
await
in front of table.updateRecordAsync
Adding the await
keyword is the easier to implement solution. However, learning to update in batches will serve you better in the long run.
Dec 31, 2021 07:58 AM
Perfect, with one word it all functioned perfectly.
I’m implementing the batch update now as recommended.
Thanks so much for the thorough response, was googling for hours, it is very much appreciated!