Switch Node AND condition

Currently the Switch-Node only supports OR conditions.
That means you can define a condition and if it matches, the output is provided to the (matching) output(s).

Actually if you have multiple conditions that requires if condition A is met and condition B is met, you need to have multiple switch-nodes stacked after each other.

For other tools I know the option to define multiple conditions (OR) and within the condition multiple AND conditions.

Sample:

Entry 1:
Condition A
Condition B
Condition C

Entry 2:
Condition D
==> Matches for (A and B and C) OR D

I think this would be a nice feature reducing the complexity and number of objects in several use-cases. :slight_smile:
What do you think about that idear?

This has been discussed before but as I remember it, in the end, a good and user friendly layout was never determined.

And then, there are lots of solutions around this. For example, a simple JSONata expression would solve the AND portion payload.A and payload.B and payload.C

1 Like

It is already on the backlog awaiting its turn.

2 Likes

Thanks @knolleary. Next time I will check against Trello :wink:

@knolleary can you estimate if this will be part of one of the next releases?

not short term unless someone steps up to help design and implement it.

Thanks @dceejay.
To be honest, I'm not much experienced in Node developement.
But maybe I can write a design. Where can I find a design template or sample designs?

Right now the switch consists of a JSON like this (example that compares payload against 2 strings):

[
    {
        "id": "145eca65.1351e6",
        "type": "switch",
        "z": "30a0ee32.740cd2",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "value1,
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "value2",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 480,
        "y": 840,
        "wires": [
            [],
            []
        ]
    }
]

Actually each line / rule already has got an output and is so to say a "OR" condition.
I could imagine to allow a rule to support multiple entries (so extend the Dictionary to an Array) and each entry is so to say handled as a boolean operator with AND condition.
Actually so the only difference would be that the rules that are currently an array of dictionaries becomes like the wires an array of arrays.

Example (only the rules, rest can stay as it is, from my understanding):

"rules": [
	[
		{
			"t": "neq",
			"v": "value3,
            "vt": "str"
        },{
            "t": "neq",
            "v": "value2,
			"vt": "str"
		}
	],
	[
		{
			"t": "eq",
			"v": "value4",
			"vt": "str"
		}
	]
]

I see the following surly complex tasks:
Migrate existing entries in rules dictionary from Dictionary to Array entries
Make the GUI able to add, edit and delete multiple entries to a rule
Adjust evaluation of the switch, that it only matches, if all entries (AND) of a rule are validated as true.

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