# Flow.set using variable

**URL:** <https://discourse.nodered.org/t/flow-set-using-variable/94093>\
**Category:** General\
**Created:** [21 December 2024 18:57 UTC](https://discourse.nodered.org/t/flow-set-using-variable/94093 "2024-12-21T18:57:38Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [21 December 2024 18:57 UTC](https://discourse.nodered.org/t/flow-set-using-variable/94093/1 "2024-12-21T18:57:38Z")

</div>

I thought this was asked before but can't find it. Is there a way , and if so how to write to flow using a variable name such as  
flow.set(MyVariable,1).  
I've got a workaround so now I'm in education mode.  
Thanks

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [21 December 2024 19:04 UTC](https://discourse.nodered.org/t/flow-set-using-variable/94093/2 "2024-12-21T19:04:49Z")

</div>

Hi @gerry ..

```auto
flow.set(<KEY>,<value>)

```

So... `<KEY>` (providing its a string) - can come from anywhere (mostly)

Think of `<KEY>` as anything that evaluates to a string (the Name of the variable)

```auto
flow.set(msg.payload.keyName,1) /* Variable Name in `msg` */
flow.set(flow.get('varName'),1) /* Variable Name from another variable */
flow.set('varName',1) /* static name */

```

---

<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:** [21 December 2024 19:30 UTC](https://discourse.nodered.org/t/flow-set-using-variable/94093/3 "2024-12-21T19:30:21Z")

</div>

So that's my problem, mine was a number sequence 1 then 2 then 3 , convert to a string should work, thanks for the pointer

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [22 December 2024 09:52 UTC](https://discourse.nodered.org/t/flow-set-using-variable/94093/4 "2024-12-22T09:52:20Z")

</div>

Just to be clear.

flow.set(\< KEY\>,\< value\>)  
Where \< KEY\> is entered with quotes or single quote  
Example flow.set(‘mykey’ , 1)

You do not need to convert integers to strings. You can use any data type. The KEY name is expressed this way as a literal. You can also use a variable which its value would hold the KEY name.

var Newkey = “mykey”;  
flow.set(Newkey,1);

---

<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:** [5 January 2025 09:53 UTC](https://discourse.nodered.org/t/flow-set-using-variable/94093/5 "2025-01-05T09:53:16Z")

</div>

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