Skip to main content
Solved

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


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

    }

Best answer by kuovonne

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.

View original
Did this topic help you find an answer to your question?

2 replies

kuovonne
Forum|alt.badge.img+17
  • Brainy
  • 5987 replies
  • Answer
  • December 31, 2021

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.


kuovonne wrote:

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!


Reply