Cannot call a function inside a foreach loop in a workflow block

list_providers.forEach(sp => {
sp.coordinates = await convert_lat_long_to_euclidiean(sp.latitude , sp.longitude);
});
I try to execute a function in my loop but it is impossible to do it.
Help me fix it please

Hey @djamara,

You can definitely call the function from a loop block but perhaps not within the callback of a .forEach().

Use the Loop node with list_providers as the loop input, use the JS Query option and then just do something like:

let resp = await convert_lat_long_to_euclidiean(value.latitude , value.longitude);
return resp

I use a few workflows where the function calls are wrapped in try/catch blocks so we can manage error handling and user follow-up.

1 Like

I figured that I cannot use foreach for this case.