Multiple items cause if node output to be abnormal

Describe the issue/error/question

A workflow process executes multiple runs and the output of the if node is not as expected.

What is the error message (if any)?

Please share the workflow

Share the output returned by the last node


Hey @Canon88,

Under the expression it tends to show you what the expressions value is for the node which is in this case is andy which does match andy so the input data to the node which is canon is going to the true branch.

So what is happening here… Well the No-Op node only has one item but 3 runs, internally when we check the data we check the items not the items for each run. This means that Run 1 will check the first item in the node, Run 2 will check the first item and so will run 3, To get around this you would need to merge the items together so you would have 1 run but with 3 items that would then possibly sort out the issue.

Here is a fixed version of the workflow that uses the items each node is passed which for what you are trying to do is the better way to handle it.

Thanks for your prompt response, I looked at the workflow for the fix. Is it using this fetching method?

{{ $json["name"] }}

Workflow similar to the production environment

In my real world environment, I might use cross-node fetching. So I can’t use $json directly in this way. That’s why I started using $node. Is there any good solution for the following workflow? My actual usage scenario is very similar to it.

In this workflow, if I use $json, I have no way to get the name data that I really want. So I have to use $node this way, but $node is obviously not the right way to grab them like this. What I’ve come up with so far is to merge them into a list.And add Split in Batches node, otherwise it will operate as many times as the number of items.

I’m not sure if the following workflow is the best solution, but with this tweak. It is working as expected. So, is there a better solution? I’m not sure if this is the “right” solution

Workflow similar to the production environment (Added Merge Node and Split Node)

Hey @Canon88,

The trick would be to merge your run data into one run with multiple items, One way to do this would be with the Merge node and another would be to use the Code node. You would then disable the run once option on the If nodes and set the expression to use {{ $("No Op").item.json["name"] }} which would use the linked item.

You can find more about this here: Built in methods and variables reference - n8n Documentation

You could if you wanted to replace the If and Set nodes with one Code node as well depending on what is happening next in the workflow.

One of the fun things with n8n is there are many ways to do the same job it just working out what makes sense and feels right for you. A lot of my first workflows are fairly messy then over time I will go back and make them nicer to look at and see if any changes improves the speed.

Thank you for answering again. I don’t have any more questions. I do agree with you that there is no standard answer for Workflow. Many times Workflow has something to do with our logic. workflow needs constant iteration and we should keep optimizing it.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.