# Trouble with flow.get

**URL:** <https://discourse.nodered.org/t/trouble-with-flow-get/16735>\
**Category:** General\
**Created:** [15 October 2019 14:37 UTC](https://discourse.nodered.org/t/trouble-with-flow-get/16735 "2019-10-15T14:37:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jstou](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@jstou](https://discourse.nodered.org/u/jstou)\
**Post date:** [15 October 2019 14:37 UTC](https://discourse.nodered.org/t/trouble-with-flow-get/16735/1 "2019-10-15T14:37:20Z")

</div>

Hi,

I am trying to use a switch in my UI and update the value of the switch (true or false) in a function node in another part of my flow. Based on the switch output, I am trying to use flow.get in the function node to set a variable. However, when I try to use flow.get, it just sets the variable in the function node to "null".

Below is my flow with the switch, and the code in the connected function node:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/29c8e3a9a8cd5bce03e96cb8458c3df7f2d0f932.png)

var btnOpOverride = msg.payload;  
msg.payload = btnOpOverride;  
return msg;

The code in the other function node in the flow looks like the following, but when I run this I get the default value for the first go around for the OperatorOverride variable, and then a "null" value the 2nd time around:

OperatorOverride = flow.get("btnOpOverride");

What am I doing wrong? I also tried some other things but nothing seems to work. I also tried doing flow.get and flow.set from the function node close to the switch, but that did not work either.

Thanks in advance for your help!

jstou

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 October 2019 14:49 UTC](https://discourse.nodered.org/t/trouble-with-flow-get/16735/2 "2019-10-15T14:49:48Z")

</div>

Somewhere you need to do  
`flow.set("btnOpOverride", somevalue)`  
otherwise `flow.get` has nothing to get.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [15 October 2019 14:58 UTC](https://discourse.nodered.org/t/trouble-with-flow-get/16735/3 "2019-10-15T14:58:22Z")

</div>

> [@jstou](#):
>
> in another part of my flow

Is this on another tab? If so, what you see is proper - go read [Working with context : Node-RED](https://nodered.org/docs/user-guide/context)

---

<div class="post-metadata">

**Author:** ![jstou](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@jstou](https://discourse.nodered.org/u/jstou)\
**Post date:** [15 October 2019 16:10 UTC](https://discourse.nodered.org/t/trouble-with-flow-get/16735/4 "2019-10-15T16:10:53Z")

</div>

Thanks for the tip! It was not clear to me in the documentation that flow.get and flow.set could be in different function nodes, I thought they had to be in the same function node. Now it makes more sense!

---

<div class="post-metadata">

**Author:** ![jstou](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@jstou](https://discourse.nodered.org/u/jstou)\
**Post date:** [15 October 2019 16:12 UTC](https://discourse.nodered.org/t/trouble-with-flow-get/16735/5 "2019-10-15T16:12:36Z")

</div>

No they are in the same flow. I've figured it out, I needed to use flow.set in the switch function node. I've read all these and they are helpful, but sometimes there is no answer online for a specific problem you are encountering...unless you ask for help on the Node Red Forum!!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 October 2019 16:31 UTC](https://discourse.nodered.org/t/trouble-with-flow-get/16735/6 "2019-10-15T16:31:43Z")

</div>

> [@jstou](#):
>
> It was not clear to me in the documentation that flow.get and flow.set could be in different function nodes

If you want to retain data for re-use only within a single node (at a later time) then use `context.get/set`, if you want it to be accessible across multiple nodes in one flow (ie editor tab) then use `flow.get/set`, if you want to be able to access the data anywhere then use `global.get/set`
