Trying to run a Resource Query within a JS Query for-loop and store each result in an object

Hey community! I'm building an app and came across an issue I haven't been able to solve. I have a JS Query that triggers a query for each row in a table. I want to grab the result of each query, create an object, push it in an array and then return the array of objects at the end.

The problem is that the objects in the array end up with the same value for the key that is being fetched from the resource query. When I assign the result of the query in a variable, the variable is undefined. The way I have it set up now, I'm just getting the same result for all the elements in the array. Any help would be much appreciated!

JS Query:

var items = [];

for (let i = 0; i <; i++) {
  var obj = {};
  obj.item_name =[i].Product;
  obj.quantity = table5.changesetArray[i].Quantity;
  query16.trigger({additionalScope: {curr:[i].Product}});
  obj.price =[0]; = obj.price * obj.quantity;

return items;

Sample result:

  • item_name:"Item 1"
  • quantity:4
  • price:55.00
  • total:220.00


  • item_name:"Item 2"
  • quantity:1
  • price:55.00
  • total:55.00

Assign the query results to a variable and add await to the front of the trigger function.

const data = await query16.trigger({additionalScope: {curr:[i].Product}})