Hi,
Previously (some weeks ago) I had a function working properly, but now I can no longer make it work. I’m not sure what changed, but I don’t recall making any change to it. Anyway…
The goal is to grab a List of Things and to apply an action on each object, getting a value from each Thing in the List of Things.
The expected behavior of the code snippet below is to console.log() a field’s value (in this case a text) once for every Thing (hence the forEach!).
However it logs the first, then restarts, logging the first again then the second, then finally the three of them. Then if you activate the workflow a second (or third, fourth…) time, it will behave as expected, which is to log the three of them at once.
It seems to have something to do with the “load all the data before taking actions”, however I can’t be sure of that. Debugging on Firefox throws me to Bubble’s standard errors after the first element gets console.log()'ed by the forEach.
To see it live, open this test app, open your web browser console to see the console.log() results, then click the big left button to generate some data then the big right button to activate the custom code.
This is all the code used in that workflow:
function(instance, properties, context) {
// Successfully retrieves a field value within every and each Thing in the List of Things.
let listOfThings = properties.fieldy_list.get(0, properties.fieldy_list.length());
let processOnEachItem = (element, index, array) => {
console.log(element.get("thing_name_text"))
}
listOfThings.forEach(processOnEachItem);
}
And here’s a link to the app editor if you want to check something.
The problem is that this snippet will be part of a much bigger action and would be insane to have the entire action repeating once for every single element in a list of things.
Any suggestions on how to defeat this?