Changing rowdata values via Javascript query

Hi,

I finished scripting my use case of iterating over 500+ rows and POSTing to Shopify APIs in order to update inventory data in Shopify.

I would like to append a "RESULTS" column to the table using a JavaScript query and update it with the JSON response data for each row. I tried just setting the value in a loop for a column I created but no dice:

table1.data.forEach(row => fetchInvId.trigger({
    additionalScope: {
        passSKU: row.SKU
    },
    onSuccess: function(data) {
        console.log(row.SKU)
        //If statement checking if the inventory item is present within the response JSON
        if (Object.values(data)[0].productVariants.edges.length == 0) {
            console.log("Item " + row.SKU + " does not exist in Shopify")
        } else {
            var shopifyInvId = Object.values(data)[0].productVariants.edges[0].node.inventoryItem.id
            shopifyInvId = /[^/]*$/.exec(shopifyInvId)[0]
            console.log(shopifyInvId)
            console.log(row.QUANTITY)
            setInventoryLevels.trigger({
                additionalScope: {
                    passLoc: locationId,
                    passInvId: shopifyInvId,
                    passQuantity: row.QUANTITY
                },
              onSuccess: function(data) {
                row.RESULTS = data
              },
              onFailure: function(data) {
                row.RESULTS = data
              }
            })
        }
    }
}))

Hi @JayC!

table1.data just returns a copy of the data object that the table1 is referencing, so any mutations on it don't get passed through to the component. One thing I tend to recommend a lot is using a temporary state. In your case, you might want to have an object containing key/value pairs where the key is a unique identifier for each row and the value is the result data for that row. Your onSuccess and onFailure function could then be something like

function(data){
   yourResultsTempState.setIn([row.yourUniqueId], data);
}

You can then create a custom column on your table that pulls that data using {{ yourResultsTempState[currentRow.yourUniqueId] }}. Does that work?