Rest api multiple query ( promise.all)

Hello, I have a question about executing Promise.all in Retool. I've configured the JavaScript as shown in the picture, but I'm unsure what values to provide in the rest API body. Can you provide guidance on this?

스크린샷 2023-12-01 125510
image

Hello, rest api resource does not have additionalScope field


You will need to store them in a variable

like: variable1.setValue([productFixedIdx, imageIdx])

and call them in your api like: {{ variable1.value[0] }} (for productFixedIdx), and {{ variable1.value[1] }} (for imageIdx)

.filter((value) => value.src === "")
.map((value) => {
variable1.setValue([collection_list_table.selectedRow.data.productIdx, Number(value.altText)])
return manage_fix_image_delete.trigger()
})
1 Like

@Oscar_Ortega
thanks for the reply
I'm currently facing an issue with asynchronous execution in JavaScript. I have an array (aaa) containing values [1, 2, 3, 4], and I'm using a loop to iterate through each value and set it using variable1.setValue(v). After setting the value, I immediately log the current value using console.log(variable1.value).

However, the problem is that the console.log(variable1.value) seems to output 4, 4, 4, 4 instead of the expected 1, 2, 3, 4. It appears that the asynchronous nature of variable1.setValue(v) might be causing the issue.

Here's the code snippet:

const aaa = [1, 2, 3, 4];

const processValues = async () => {
  for (const v of aaa) {
    await variable1.setValue(v);
    console.log(variable1.value);
  }
};

processValues();

image

Hey @cmlee! Yes, asynchronicity definitely plays a part here but you've handled that well by awaiting the call to setValue. For performance purposes, by default, the value of external (to the JS query) variables is only read when the JS query is initially called. In order to refresh the value within the JS query itself, you need to check the Keep variable references inside the query in sync with your app. checkbox on the advanced tab of the query editor.

Here's this JS query run without and with that checkbox checked.

Hope this helps clarify what's going on!

1 Like