Looper v2 - looping the list two times

Hello,

I have an issue when using the looper v2 custom widget, the looper and its function is working as it should. However, for some reason the looper is carrying out the tasks on the looping list twice, it successfully completes the first loop but then the iteration goes to zero and starts climbing again, resulting in a 2nd loop. For some reason though the looper fails while doing the second loop only before the last event on the looping list.

I have tried to manually set the iteration to zero at the end of loop but to no avail,

Has anyone experienced something similar? And if yes, how did you solve this issue?

Thank you and regards,

Jean Claude Mercieca

Hi @Jean1 & welcome to Tulip Community :tulip: :tada:

A question for you here:
Are you using the looper widget on step enter by chance? If so, we would recommend avoiding this, as it can cause some issues. If for your use case, you must do a step enter trigger for the looper, it would be best to place it on the base layout so that the widget doesn’t reload.

If you haven’t already, you can also check out this video that demos how the looper should work and just make sure everything is set up correctly on your end!

Las thing, depending on your use case, you may want to consider Automations Looping (which is a new feature)!

https://support.tulip.co/docs/how-to-use-looping-in-automations

@Jean1 I noticed this same issue too as I setup a looper on one step and then transition to a new step where the looper is located.

Based on the simple test in the Custom Widget editor I found the looper runs twice if the Boolean value is already set to YES when the custom widget loads. If instead the value is changed to yes later after loading the issue is not present.

The “simple” solution is to put a button that starts the looper when clicked.

In my case this won’t work either since I have 3 loopers that run is succession. One day a user clicked the button twice and started the series of looper a second time causing quite a data issue for me. :frowning:

I purposely have no buttons of any kind on this step to reduce the risk of users existing out or changing steps (or restarting the loopers) while the loopers are running. The last looper to run will transition the user to a new step once complete. If a looper has an error the user will get stuck here but then they will need to seek help thus alerting me that there could be a data issue.

So, I’m considering updating the Looper JavaScript to prevent this issue allowing me to run the looper on step start.

Another option could be to use a second Boolean variable to track if the button has been clicked…if it was clicked than don’t allow a second click even if the looper is ready to be triggered a second time.

1 Like

I might oversee something but, I guess the fix for the code is as simple as that:

Just add the highlighted check.
The issue is, when the widget is loaded, it will check for the start boolean (and starts the loop, if true) AND checks the iteration (and starts the loop, if not undefined or null).

So if the start boolean is true and the iteration is 0, both will trigger the start of the loop.

When adding the iteration beeing >0 this should only trigger the start once.

5 Likes

Thank you @thorsten.langner that definitely seems to have fixed it!

2 Likes

Thank you all for your replies!

The solution from @thorsten.langner seems to have fixed it.

2 Likes