Save the date! Join us on October 16 for our Product Ops launch event. Register here.
May 31, 2022 10:32 PM
Hello, i am setting up a Google Apps Script to update some records from our student information system. I was able to set up an array of records in the required format for patching the data in Airtable, i also got it to work, however whenever there are more than 10 records i get an error, so i am trying to figure out the best way to process them 10 at a time using plain JS or Google App Script. I was thinking of implementing a for loop to send a patch request for every record, but that did not seem like the smart way to do it. I wondering what was the best way to break it down 10 at a time
Thanks
Anto
Solved! Go to Solution.
Jun 01, 2022 01:14 PM
Standard practice for using Airtable Scripting’s .updateRecordsAsync()
which lets you update 50 records at a time generally follows this format:
let updates = []
while (updates.length > 0) {
await table.updateRecordsAsync(updates.slice(0, 50));
updates = updates.slice(50);
}
So perhaps try
let updates = []
while (updates.length > 0) {
base('Table Name').update(updates.slice(0, 10));
updates = updates.slice(10);
}
Jun 01, 2022 01:14 PM
Standard practice for using Airtable Scripting’s .updateRecordsAsync()
which lets you update 50 records at a time generally follows this format:
let updates = []
while (updates.length > 0) {
await table.updateRecordsAsync(updates.slice(0, 50));
updates = updates.slice(50);
}
So perhaps try
let updates = []
while (updates.length > 0) {
base('Table Name').update(updates.slice(0, 10));
updates = updates.slice(10);
}
Jun 01, 2022 01:23 PM
You will also need to make sure that you do not exceed the REST API rate limit of 5 requests per second. If you always wait until you get a response before sending the next batch, you will probably not exceed this rate limit. On the other hand, you might run into other limits from the GAS side. (I’m not familiar enough with GAS to say for sure.)