Help

Re: Script is only moving some of the records, despite console stating otherwise

Solved
Jump to Solution
1085 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Alexander_Ahlen
4 - Data Explorer
4 - Data Explorer

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…
Screenshot 2021-12-31 120834
Screenshot 2021-12-31 120953

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')
    }
1 Solution

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

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

  • add the keyword await in front of table.updateRecordAsync
  • update the records in batches, instead of one at a time. See the Find & replace example script for one way to do this.

Adding the await keyword is the easier to implement solution. However, learning to update in batches will serve you better in the long run.

See Solution in Thread

2 Replies 2
kuovonne
18 - Pluto
18 - Pluto

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

  • add the keyword await in front of table.updateRecordAsync
  • update the records in batches, instead of one at a time. See the Find & replace example script for one way to do this.

Adding the await keyword is the easier to implement solution. However, learning to update in batches will serve you better in the long run.

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!