How to implement IF after Comparison node?

Describe the problem/error/question

I want to be able to execute branch even if output of comparison node is empty.
E. g. I compare existing data in DB with new fetched. And using Comparison node to extract only new data. So if there is new data — Comparison node output propagates data further. And everything is ok.
But if there are no new data — comparison node just stops.
And I want to put IF after comparison node. And if there is no new data — do one thing. And if there is new data — do something else.
I know how to implement it manually via Code.
But is there any way without manual coding!
P.S.
“Always output data” is enabled

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Is continue on fail enabled as well?

Tested. Same behaviour. Technically empty comparison output is not error. So node shows green checkmark and stops

Perhaps you want to consider using a Filter node here (or multiple Filter nodes depending on your requirements)? This node provides functionality similar to the IF node, but only has a single output. Provided you enable the Always Output Data option it would continue the execution even if the comparison fails:

Hi!
Does Filter allows to filter on logic based on 2 inputs?

What I need in general:
Node 1 outputs e.g [1,2,3]
Node 2 outputs [1,2,3,4,5]

So Compare allows me to substract Node 1 from Node 2. And get result [4,5]
So everything works ok. Except when result of comparison is empty (when both lists are equal). In this case compare just stops execution.

So how to implement this logic with filter?

Perhaps you can share a workflow demonstrating your problem? [1,2,3] wouldn’t be the typical data structure returned by an n8n node, so I suspect we might be missing something relevant here.

Hi! Sorry for confusion. Saying [1,2,3] I meant it in more general sense.
Here is example workflow. Upper shows case when flow continues execution after Compare node. And lower workflow shows case, when flow stops after comparison

Hey @kimsanov,

The flow stops because there is no data coming out of the “In B only Branch”, In the test you are using if A==B then the data would be correctly routed to the “Same Branch”.

What is interesting though is always output data seems to always output on the first branch rather than all of them but at the same time if we did always output data it will likely lead to some very unexpected results.

I will create a dev ticket anyway to always output data on all branches and we can see what the outcome is.

Hi! Thanks for dev ticket.

My general thoughts is that Comparison behaves like set maths. I.e. if sets A and B are equal, then A - B should return empty set instead of returning nothing.
Let’s see what devs think about that

1 Like

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