Skip to main content
Solved

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

  • June 1, 2022
  • 2 replies
  • 42 views

Forum|alt.badge.img+7

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

Best answer by Kamille_Parks11

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

2 replies

Kamille_Parks11
Forum|alt.badge.img+27
  • Brainy
  • 2679 replies
  • Answer
  • June 1, 2022

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

kuovonne
Forum|alt.badge.img+29
  • Brainy
  • 6009 replies
  • June 1, 2022

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