4 Possible inputs into one output

Hello,

I have one Item as input

[
{
“hasName”: true,
“itemId”: 12639,
“hasName2”: true,
“itemId2”: 12640
}
]

Now I want to have 4 different possible routes which should end in one with two items but they should be one so I have no two different runs.

I tried with a switch which should do the job but this switch did only gave me one output route and the other did not output. E.g. configured like hasName = true and hasName2 = true and the same for false. But when hasName was true und hasName2 false it did only output at hasName = true and hasName2 = false did not.

So I did have a look in the forum here and someone suggested to work with filters. This works but then I get two items as output.

Is there a more elegant way to do what I want todo here? :blush:

I use version 1.33.1 (self Hosted)

This is a part of the scenario

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

@Sebastian1 , all the states of your “object” could be described by 2-bits binary number:

hasName  hasName2
-----------------
true     true
false    true
true     fasle
false    false

In other words, those 4 states could be represented as binary (== decimal):

0b11 == 3:  hasName and hasName2 are true
0b01 == 1:  only hasName2 is true
0b10 == 2:  only hasName is true
0b00 == 0:  hasName and hasName2 are false

If your Code node adds this binary number (or equivalent decimal) representing the state, you can check the state of your object with switch as below.

Note that only one Switch output will be at play here.

Does it look simpler to you?

3 Likes

@ihortom thank you for that idea. This works well! When I did understand it it does look simpler now yes. But took some minutes :slight_smile:

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