# Using variables in flow set and get

**URL:** <https://discourse.nodered.org/t/using-variables-in-flow-set-and-get/78387>\
**Category:** General\
**Created:** [12 May 2023 15:26 UTC](https://discourse.nodered.org/t/using-variables-in-flow-set-and-get/78387 "2023-05-12T15:26:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![talesmaschio](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@talesmaschio](https://discourse.nodered.org/u/talesmaschio)\
**Post date:** [12 May 2023 15:26 UTC](https://discourse.nodered.org/t/using-variables-in-flow-set-and-get/78387/1 "2023-05-12T15:26:30Z")

</div>

Hello guys,

Sorry, this is probably something very well known to the more experienced but I couldn't find anything about so here I am.

Is it possible to use indirect referencing to variable names in context/flow/global get and set commands? I have a situation where I'll have around 60 variables that will be read/written to one at a time, and I'd like to use the same function node to do it all.

I'll receive the name of the variable as a string in `msg.payload.id`, here's an example of the kind of logic I'd like to use:

```auto
var id = msg.payload.id;
var alive = id + "_alive";
var checkalive = flow.get(alive);
var down = id + "_down";
var checkdown = flow.get(down);
...
flow.set(alive, true);
flow.set(down, false);

```

`msg.payload.id` will always be a 3 char code like IMP, SUP, MTE, etc. So I want to end referencing variables IMP\_down, IMP\_alive, etc.

Is this possible?

Thank you all!

---

<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 May 2023 15:40 UTC](https://discourse.nodered.org/t/using-variables-in-flow-set-and-get/78387/2 "2023-05-12T15:40:42Z")

</div>

> [@talesmaschio](#):
>
> Is it possible to use indirect referencing to variable names in context/flow/global get and set commands?

Yes, you do that in your example with the variable `alive`

> [@talesmaschio](#):
>
> ```auto
> var id = msg.payload.id;
> var alive = id + "_alive";
> var checkalive = flow.get(alive);
> 
> ```

If that is not working, use `node.warn('alive = ' + alive)` to see what it contains.

---

<div class="post-metadata">

**Author:** ![talesmaschio](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@talesmaschio](https://discourse.nodered.org/u/talesmaschio)\
**Post date:** [12 May 2023 16:38 UTC](https://discourse.nodered.org/t/using-variables-in-flow-set-and-get/78387/3 "2023-05-12T16:38:16Z")

</div>

Forget it, in the rush I was writing to the wrong variable, checkalive instead of alive, and was correctly getting a `wrong context key error`. I knew it had to be something stupid on my side, I just wasn't findind it.

Thank for the help.  
Regards,  
Tales

---

<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:** [26 May 2023 16:39 UTC](https://discourse.nodered.org/t/using-variables-in-flow-set-and-get/78387/4 "2023-05-26T16:39:10Z")

</div>

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