# Switch Node AND condition

**URL:** https://discourse.nodered.org/t/switch-node-and-condition/43088
**Category:** Feature Requests
**Created:** [23 March 2021 15:41 UTC](https://discourse.nodered.org/t/switch-node-and-condition/43088 "2021-03-23T15:41:41Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![crackytsi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crackytsi/32/28369_2.png) [@crackytsi](https://discourse.nodered.org/u/crackytsi)
#### Post date: [23 March 2021 15:41 UTC](https://discourse.nodered.org/t/switch-node-and-condition/43088/1 "2021-03-23T15:41:42Z")

</div>

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. 🙂  
What do you think about that idear?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [23 March 2021 15:49 UTC](https://discourse.nodered.org/t/switch-node-and-condition/43088/2 "2021-03-23T15:49:04Z")

</div>

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`

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [23 March 2021 16:00 UTC](https://discourse.nodered.org/t/switch-node-and-condition/43088/3 "2021-03-23T16:00:47Z")

</div>

> [@crackytsi](#):
>
> What do you think about that idear?

It is already on the backlog awaiting its turn.

https://trello.com/c/vkrqUBRi.html

---

<div class="post-metadata">

### Author: ![crackytsi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crackytsi/32/28369_2.png) [@crackytsi](https://discourse.nodered.org/u/crackytsi)
#### Post date: [23 March 2021 20:04 UTC](https://discourse.nodered.org/t/switch-node-and-condition/43088/4 "2021-03-23T20:04:08Z")

</div>

Thanks @knolleary. Next time I will check against Trello 😉

---

<div class="post-metadata">

### Author: ![crackytsi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crackytsi/32/28369_2.png) [@crackytsi](https://discourse.nodered.org/u/crackytsi)
#### Post date: [19 May 2021 17:49 UTC](https://discourse.nodered.org/t/switch-node-and-condition/43088/5 "2021-05-19T17:49:48Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [19 May 2021 18:06 UTC](https://discourse.nodered.org/t/switch-node-and-condition/43088/6 "2021-05-19T18:06:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![crackytsi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crackytsi/32/28369_2.png) [@crackytsi](https://discourse.nodered.org/u/crackytsi)
#### Post date: [19 May 2021 19:05 UTC](https://discourse.nodered.org/t/switch-node-and-condition/43088/7 "2021-05-19T19:05:56Z")

</div>

> [@dceejay](#):
>
> up

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):

```auto
[
    {
        "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):

```auto
"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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [18 July 2021 19:05 UTC](https://discourse.nodered.org/t/switch-node-and-condition/43088/8 "2021-07-18T19:05:59Z")

</div>

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