Help

Save the date! Join us on October 16 for our Product Ops launch event. Register here.

Patch 10 records at a time from an array of 100 records

Topic Labels: Scripting extentions
Solved
Jump to Solution
2407 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Antony_Rappai
5 - Automation Enthusiast
5 - Automation Enthusiast

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

1 Solution

Accepted Solutions
Kamille_Parks
16 - Uranus
16 - Uranus

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);
}

See Solution in Thread

2 Replies 2
Kamille_Parks
16 - Uranus
16 - Uranus

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);
}

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.)