Loop Node Only Processes the First Item - How to Fix?

Hey @Gustavo_Borges,

I have just picked this one up, The loop node can be tricky at times. So in this case the reset option needs to be used to tell the Loop node that it is a new set of data but as you probably noticed while testing if you just enable reset it will run forever as it will reset for every item that comes in from the loop branch.

This brings the new question… How do I reset it for the second run of items? The example workflow that @ihortom gave us is below, In this workflow we will want to run the output of the Debug Helper in the loop twice but without the reset we get the issue you are seeing.

So to change this and reset the data properly we want to make sure that we only reset the data if the node that ran before it is the If node that way when the code node loops back we don’t continue with the first item. To do this we open the Loop node and add the reset option but change it to use an expression, For the value of the expression we use {{ $prevNode.name === 'If' }} so if the previous node name is if we return true which will reset it.

image

So now when we run the workflow we get this…

It has done 14 runs of the loop node (1 for each item and 1 for each done branch) and we have the 12 items being processed correctly.

Let me know if this helps or if you have any other questions on this.

6 Likes