# If 1 message ... if 2 messages

**URL:** <https://discourse.nodered.org/t/if-1-message-if-2-messages/58753>\
**Category:** General\
**Created:** [21 February 2022 14:51 UTC](https://discourse.nodered.org/t/if-1-message-if-2-messages/58753 "2022-02-21T14:51:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miliano](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Miliano](https://discourse.nodered.org/u/Miliano)\
**Post date:** [21 February 2022 14:51 UTC](https://discourse.nodered.org/t/if-1-message-if-2-messages/58753/1 "2022-02-21T14:51:59Z")

</div>

Hello 🙂

I have a little problem and can´t find a solution. Hope you can give me a tip.

I need something like this:

Input: message a -\> Output message a  
Input: message b -\> Output message b  
Input: message a + message b (in a given time) -\> Output message a  
Input: message b + message a (in a given time) -\> Output message a

And the last one is my problem. The other 3 thinks work with a delay node, but I have no idea, what i can use, do to get all four thinks done.

Please give me a little input. Also a keyword to search is welcome, because I cant explain google what I want to find! 😉

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 February 2022 17:19 UTC](https://discourse.nodered.org/t/if-1-message-if-2-messages/58753/2 "2022-02-21T17:19:50Z")

</div>

How would you determine which is message a and message b? do you know the what the messages would be? can they be identified in any way?

---

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [21 February 2022 17:31 UTC](https://discourse.nodered.org/t/if-1-message-if-2-messages/58753/3 "2022-02-21T17:31:22Z")

</div>

Your 2nd and 4th option may conflict.

If 4th, Input: message b + message a (in a given time) -\> Output message a

Do you still want to output message b due to the 2nd condition and then output message a as well? Or just message a?

---

<div class="post-metadata">

**Author:** ![Miliano](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Miliano](https://discourse.nodered.org/u/Miliano)\
**Post date:** [21 February 2022 20:00 UTC](https://discourse.nodered.org/t/if-1-message-if-2-messages/58753/4 "2022-02-21T20:00:31Z")

</div>

Thanks for reply! 🙂

@ E1cid - Identify the messages is no problem. There will be a part in the message witch exactly say it is message a or b.

@ HaroldPetersInskipp - You are right. It has to be: Input: message b (in a given time) -\> Output message b

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 February 2022 20:46 UTC](https://discourse.nodered.org/t/if-1-message-if-2-messages/58753/5 "2022-02-21T20:46:48Z")

</div>

Would of been nice to see these messages.

Here is an example, may help

```auto
[{"id":"2cb79f6d.89d9e","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":\"a\",\"payload\":1}","payloadType":"json","x":150,"y":1500,"wires":[["aa5af8be.431c08"]]},{"id":"aa5af8be.431c08","type":"join","z":"bf9e1e33.030598","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":320,"y":1500,"wires":[["b8726ad6.5804d8"]]},{"id":"b8726ad6.5804d8","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$count($$.payload)=1 ? $$.payload[0] : \"a\" in $$.payload.id ? $$.payload[id = \"a\"][0] : $$.payload[id =\"b\"][0]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":1500,"wires":[["2c7ddea7.0f6dca"]]},{"id":"ecf1849d.e31508","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":\"b\",\"payload\":2}","payloadType":"json","x":130,"y":1540,"wires":[["aa5af8be.431c08"]]},{"id":"2c7ddea7.0f6dca","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":720,"y":1500,"wires":[]}]

```

the time between messages is set in the join timeout for less than a second use decimals e.g. 0.5

Or similar with objects joined.

```auto
[{"id":"2cb79f6d.89d9e","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":\"a\",\"payload\":1}","payloadType":"json","x":150,"y":1500,"wires":[["aa5af8be.431c08"]]},{"id":"aa5af8be.431c08","type":"join","z":"bf9e1e33.030598","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"payload.id","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":320,"y":1500,"wires":[["b8726ad6.5804d8"]]},{"id":"ecf1849d.e31508","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":\"b\",\"payload\":2}","payloadType":"json","x":150,"y":1540,"wires":[["aa5af8be.431c08"]]},{"id":"b8726ad6.5804d8","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$count($$.payload.*) = 1 ? $$.payload.* : $$.payload.*[id = \"a\"]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":1500,"wires":[["2c7ddea7.0f6dca"]]},{"id":"2c7ddea7.0f6dca","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":1500,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Miliano](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Miliano](https://discourse.nodered.org/u/Miliano)\
**Post date:** [21 February 2022 22:42 UTC](https://discourse.nodered.org/t/if-1-message-if-2-messages/58753/6 "2022-02-21T22:42:44Z")

</div>

Thanks a lot! Not only a tip, a whole example ... perfect!  
Now I have something I can work with. 🙂  
Will have a look if it works for me 😉

---

<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:** [22 April 2022 22:43 UTC](https://discourse.nodered.org/t/if-1-message-if-2-messages/58753/7 "2022-04-22T22:43:29Z")

</div>

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