# Trying to make a if function work

**URL:** <https://discourse.nodered.org/t/trying-to-make-a-if-function-work/34691>\
**Category:** General\
**Created:** [22 October 2020 19:17 UTC](https://discourse.nodered.org/t/trying-to-make-a-if-function-work/34691 "2020-10-22T19:17:05Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [22 October 2020 19:30 UTC](https://discourse.nodered.org/t/trying-to-make-a-if-function-work/34691/2 "2020-10-22T19:30:33Z")

</div>

Hi @niceguy45 welcome to the forum!

Well assuming that both `msg.id` & `msg.payload` arrive at the same time, then your code works for me. See -

```auto
[{"id":"157eccae.ee3a93","type":"inject","z":"c53060.842a0fa","name":"","props":[{"p":"payload"},{"p":"id","v":"222","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":140,"y":1350,"wires":[["3b61ed35.e45e42"]]},{"id":"b490915a.67398","type":"debug","z":"c53060.842a0fa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":540,"y":1350,"wires":[]},{"id":"3b61ed35.e45e42","type":"function","z":"c53060.842a0fa","name":"","func":"msg.test=\"OK\";\nif ( (msg.id == 222 && msg.payload == true) || ( msg.id == 220 && msg.payload == true) ){\nreturn msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":1350,"wires":[["b490915a.67398"]]},{"id":"7b65e10f.83712","type":"inject","z":"c53060.842a0fa","name":"","props":[{"p":"payload"},{"p":"id","v":"222","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":140,"y":1400,"wires":[["3b61ed35.e45e42"]]}]

```

PS - if you share any code or flows, [please see this post](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506) which describes how to post it (as the forum software changes it!)

---

_[View the full topic](https://discourse.nodered.org/t/trying-to-make-a-if-function-work/34691)._
