How to execute sql queries using js/transformer

You don't need to use the GUI.

if (dataArray && dataArray.length > 0) {
  // Iterate through the dataArray and generate SQL update statements
  dataArray.forEach((row) => {
yourUpdateQuery.trigger({
  additionalScope: {
    quote_adjustment: ${row.quote_adjustment},
    Quotation_no: ${row.Quotation_no},
    SKU: ${row.SKU}
  },
  // You can use the argument to get the data with the onSuccess function if you want to
  onSuccess: function (data) {
    console.log("Successully ran!");
  },
});
}

Then in yourUdateQuery resource, simply pass in
UPDATE table SET quote_adjustment = {{quote_adjustment}} WHERE Quotation_no = {{Quotation_no}} AND SKU = {{SKU}}

You may not need the OnSuccess argument....

You should also consider using Promises....

1 Like