Split in Batches Strange Behavior

Hello.

Can someone explain me and tell me why it behaves like that split in batces node according to the following scenario?

You can see if you run it that the nodes Set3 and Set5 produces wrong results.

Why is that happening if there is an intermediate node before the loop point and the last 2 results of these nodes are duplicates?

Aren’t suppose to have all Set nodes the same results?

In your example, Split3 loops to itself before the item gets passed on. In Set3 you are then not looking at the incoming data but at the value the corresponding Item from Split3. If you simply change the expression used in Set3 from {{$node["Split3"].json["Customers"]}} to {{$json["Customers"]}} to use the actual incoming data rather than whatever Split3 is currently looking at, you would have the desired output.

This also goes for Set5, you aren’t using the data coming in in Set5 but are referencing data from Split4 (which loops to the next item before Set5 is reached).

So just looking at the incoming items at each of your Set nodes (= using $json instead of $node) would avoid such trouble.

On a more general note, looping is often not required and complicates things a lot. So it’s always good to keep this list in mind.

1 Like

Thank you very much for your explanation.

Now i understand the logic and i will try to fix my other workflows too.

1 Like

Glad to hear this helps, thanks a lot for confirming!

On a side node, the input data can also be added through the expression editor, so you don’t have to type it manually. You can find it under Current Node > Input Data > JSON:

Hope this helps :slight_smile:

@MutedJam

Can you look this example:

What can you do when you have an intermidiate node that produces different data?

How can you get the correct data from Split Batch then?

You have to start the loop from the Set2 or else there is not other way?

Well, in this example a loop wouldn’t be required - the set nodes would run once for each input item even without Split in Batches:

But assuming you do need a loop, I would indeed loop after your Set2 node as you have suggested:

Example Workflow
1 Like

Thank you.

Really appreciate it.

1 Like