How to do an action based on the results of each REST call in a loop

I had kinda same issue where i needed to loop trough a table/ my customers and then run a query which assigns 2 different queries, maybe you can tweak it to fit.

return Promise.all(
  //data to get ids'
  allCustomerSort.data.map(async (row) => {
      //get address data from query
      const address = await customerAdresse.trigger({
        additionalScope: {
        customerid: row.id,
      }}); 
      
      //assign so that row values will overwrite address values when they're the same (e.g. id)
      //you can totally use a more nuanced assignment here though

      return Object.assign(address.value.postalAddress, row); 
   })
);

2 Likes