Help

Re: Update Multiple records - Script

554 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Ujval_Shah
5 - Automation Enthusiast
5 - Automation Enthusiast

I have an external API using, which I’m getting a list of the items.
Items object/array is having a field name = title
I want to update only records for which title matches
AT also have a field name “title”
but this is not working as expected. it;s not aligning the correct records.

let table = base.getTable('Data');
let view = table.getView("CMS Data");
let query1 = await view.selectRecordsAsync({
    sorts: [
       {field: "Title"},
    ]
});

let response = await fetch('https://<api-url>/endpoint?_format=json', {
    //method: 'GET',
});

let query = await response.json();
let peopleTable = base.getTable('Content');

for (var i in query) {
    recordId = query1.records[i].id;
    if( query1.records[i].getCellValue("Title") == query[i].title ) {
        let cms_id = query[i].id;
        await peopleTable.updateRecordAsync(recordId, {
            "id": Number(cms_id),
        })
    }
}
1 Reply 1

Your script is using the same index for both the data from Airtable and the API. However, the indexes for the two datasets do not align. They might even be different lengths.

I suggest you read Bill French’s post on how to deal with situations like this.