Help

UpdateRecordsAsync is skipping some updates

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

Hiya AT community, I was hoping someone would be able to shed some light on my issue, as I haven't been able to solve this one on my own!

I have a script that is performing some updates to a stocktake via a script. It will find matching items and then update the value in the number field. My confusion here is that it is working for one field and not the other field, I have tried different strategies to try and get an error or figure out why, but the field ID is defs correct and the field name used instead also produces the same result. Any advice would be appreciated 🙂

I'll try add the relevant code to the issue..

This if statement works as expected

 

if (newStockMatches){
        if(storageLocation == "Warehouse"){
            console.log(newStockMatches.id);
            recordsToAddStock.push({
            id: newStockMatches.id,
            fields: {
                'FIELD ID IN STRING FORMAT': newStockMatches.getCellValue('FIELD ID IN STRING FORMAT') + qty // Warehouse field ID
                    }
                }
            ); 
        }else if(storageLocation == "Office"){
            console.log(newStockMatches.id);
            recordsToAddStock.push({
            id: newStockMatches.id,
            fields: {
                'FIELD ID IN STRING FORMAT': newStockMatches.getCellValue('FIELD ID IN STRING FORMAT') + qty // Office field ID
                    }
                }
            ); 

 

The console output from creating that array gives me what I expect.

 

(2) [Object, Object]
0: Object
id: "RECORD ID"
fields: Object
FIELD ID: 440
1: Object
id: "THE SAME RECORD ID"
fields: Object
DIFFERENT FIELD ID: 905

 

I then loop through to batch update, in case we have more than 50 records to update at some point..

 

while (recordsToAddStock.length>0) {
    await stocktakeTable.updateRecordsAsync(recordsToAddStock.slice(0,50));
    recordsToAddStock = recordsToAddStock.slice(50);
}

 

In this case the first field is not updating, but the second field is. I am not sure if it is something to do with them being the same record or not, but I can't work this one out.
It's running, not failing, and providing the output I expect in the console, but then not behaving as I expected. - The worst kind of bug 😅

1 Solution

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

Since both updates are for the same record, you should put both updates in the same record update object, instead of pushing two different updates for the same record. 

See Solution in Thread

2 Replies 2
kuovonne
18 - Pluto
18 - Pluto

Since both updates are for the same record, you should put both updates in the same record update object, instead of pushing two different updates for the same record. 

Katieglamer
5 - Automation Enthusiast
5 - Automation Enthusiast

Thank you for your help! That's very annoying given this particular situation, but that does solve my problem 😁