# AND condition in node-red block

**URL:** https://discourse.nodered.org/t/and-condition-in-node-red-block/64994
**Category:** General
**Created:** [12 July 2022 08:39 UTC](https://discourse.nodered.org/t/and-condition-in-node-red-block/64994 "2022-07-12T08:39:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![denissanga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/denissanga/32/48346_2.png) [@denissanga](https://discourse.nodered.org/u/denissanga)
#### Post date: [12 July 2022 08:39 UTC](https://discourse.nodered.org/t/and-condition-in-node-red-block/64994/1 "2022-07-12T08:39:05Z")

</div>

Hi all, I would like create AND condition with many node input. If all are true then pass to node after.

I'm trying using SWITCH function but i think it is not usefull for this application.  
Do you have some suggestions?  
many thanks in advance

---

<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: [12 July 2022 08:53 UTC](https://discourse.nodered.org/t/and-condition-in-node-red-block/64994/2 "2022-07-12T08:53:29Z")

</div>

> [@denissanga](#):
>
> I would like create AND condition with many node input. If all are true then pass to node after

The first (and most important) thing to understand is that 1 `msg` travels down 1 wire at a time. This means messages NEVER arrive from multiple wires to a node at the same time.

This leaves you with the thought - how do I get all messages into a switch/function at once? The answer is to either store them until all are received OR use a join node.

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

Once you have all data in one object, you can then compare the parts

e.g. in a function

```javascript
if(msg.payload.m1.value === true && msg.payload.m2.value === true && msg.payload.m3.value === true) {
    msg.payload = true
} else {
    msg.payload = false
}
return msg;

```

---

<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: [10 September 2022 08:53 UTC](https://discourse.nodered.org/t/and-condition-in-node-red-block/64994/3 "2022-09-10T08:53:57Z")

</div>

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