Logging a triggered query's success/failure message in a table component and then download as csv

const loanRows = uploadProducts.data
let errors = "";
let table5 = [];


// declare function to trigger query
function createProduct (counter) {
  if (counter >= loanRows.length) {
    console.log("Finished running all queries");
  } else {
    createProducts.trigger({
      additionalScope: {i: counter},
      onSuccess: function (data) {
    //call function
    createProduct(counter + 1);
    },
    onFailure: function () {
      // create logs
    let newObj = {};
    newObj.merchantID =  uploadProducts.data[counter].merchantId;
    newObj.name =  uploadProducts.data[counter].name;
    newObj.error = createProducts.data.message;
  
    // add row to logs table
    table5.push(newObj);
      //call function
    createProduct(counter + 1);
    },
    })
     }
}
// call function
createProduct(0);
// return logs table
return table5;

i have this process where i want to iterate over a table component , then perform a trigger operation to using a query to post those items in the table to a database endpoint, i am trying to identify rows that failed the query operation and store them in a table component in retool. my current process doesnt seem to work, can someone please shed light on another way to achieve? or help me figure out why the on failure block of the code does'nt return an object array.

Hey @ughanze23!

Using that pattern the whole JavaScript query actually returns before your triggered queries are done running. To collect results you can try something like collecting them in a temp state by including the following in your failure handler after pushing the new error object:

yourTempState.setValue(table5);  

Does that work?

i can't find how to create a tempstate, the documentation mentions something at the bottom panel but i can't find it.

As of version 2.92 you should be able to find it here:

This wasn't always the case tough! In older versions of Retool it exists at the top of the left panel:

ok thanks, but sadly it didnt work.

:thinking: what are you seeing in the tempstate after running the query? Also curious to see the stack of queries being run in your debug console: