# Need assistance with a function

**URL:** <https://discourse.nodered.org/t/need-assistance-with-a-function/51368>\
**Category:** General\
**Created:** [22 September 2021 01:05 UTC](https://discourse.nodered.org/t/need-assistance-with-a-function/51368 "2021-09-22T01:05:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![k5map](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/k5map/32/47681_2.png) [@k5map](https://discourse.nodered.org/u/k5map)\
**Post date:** [22 September 2021 01:05 UTC](https://discourse.nodered.org/t/need-assistance-with-a-function/51368/1 "2021-09-22T01:05:44Z")

</div>

I have a very simple function but for some reason it is not working as I expected... I've attached a screenshot of the function. Via Debug messages, I've confirmed global.Rain is true and msg.payload.value = "on" but the function only returns null. What am I missing?  
 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/f/2f5929c25557904b1b8013694caa074ac2d9b0a3.jpeg)

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [22 September 2021 01:11 UTC](https://discourse.nodered.org/t/need-assistance-with-a-function/51368/2 "2021-09-22T01:11:41Z")

</div>

One thing is that when looking for true/false you should use "===", small thing but.....

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [22 September 2021 02:40 UTC](https://discourse.nodered.org/t/need-assistance-with-a-function/51368/3 "2021-09-22T02:40:29Z")

</div>

Do some troubleshooting with node.warn(variable). E.g:

Add the line node.warn(global) as well as node.warn(global.Rain) in the very beginning of your code (before the if statement). Most likely you will get something different from what you expect.

If you stored the variable "Rain" in the global context you should recover it with global.get("Rain") instead of global.Rain.

---

<div class="post-metadata">

**Author:** ![k5map](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/k5map/32/47681_2.png) [@k5map](https://discourse.nodered.org/u/k5map)\
**Post date:** [22 September 2021 02:54 UTC](https://discourse.nodered.org/t/need-assistance-with-a-function/51368/4 "2021-09-22T02:54:16Z")

</div>

@Andrei ... I was using the same var name I used in the other nodes and forgot I needed to change with the function. Great catch, thanks.

---

<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:** [6 October 2021 02:54 UTC](https://discourse.nodered.org/t/need-assistance-with-a-function/51368/5 "2021-10-06T02:54:50Z")

</div>

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