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 < table5.data.length; i++) {
var obj = {};
obj.item_name = table5.data[i].Product;
obj.quantity = table5.changesetArray[i].Quantity;
query16.trigger({additionalScope: {curr:
table5.data[i].Product}});
obj.price = query16.data.retail_price[0];
obj.total = obj.price * obj.quantity;
items.push(obj);
}
return items;
Sample result:
1
- item_name:"Item 1"
- quantity:4
- price:55.00
- total:220.00
2
- item_name:"Item 2"
- quantity:1
- price:55.00
- total:55.00