# Flow Set $parent.\<Dynamic Name\>

**URL:** <https://discourse.nodered.org/t/flow-set-parent-dynamic-name/96705>\
**Category:** General\
**Created:** [22 April 2025 16:05 UTC](https://discourse.nodered.org/t/flow-set-parent-dynamic-name/96705 "2025-04-22T16:05:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HarryPottar](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@HarryPottar](https://discourse.nodered.org/u/HarryPottar)\
**Post date:** [22 April 2025 16:05 UTC](https://discourse.nodered.org/t/flow-set-parent-dynamic-name/96705/1 "2025-04-22T16:05:35Z")

</div>

Hello,

I'm storing the flow context in the parent for a subflow.

I need to name the variable dynamically based on a login name.

```auto
let userName = env.get("USERNAME");
if (msg.hasOwnProperty('UserName')) userName = msg.UserName;

let wSession = {};

wSession.session = "JSESSIONID=" + msg.payload.result.sessionID;

msg.wSession = wSession.session

flow.set("$parent.userName", wSession );

```

This does not work of course, the flow is stored against the property userName and not the value of userName.

Thanks  
Harry

---

<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:** [22 April 2025 21:06 UTC](https://discourse.nodered.org/t/flow-set-parent-dynamic-name/96705/2 "2025-04-22T21:06:03Z")

</div>

> [@HarryPottar](#):
>
> `flow.set("$parent.userName", wSession );`

Something like

```auto
flow.set(`$parent.${userName}`, wSession )

```

You could rewrite the first lines as  
`const userName = msg.UserName ?? env.get("USERNAME")`

and, personally I would also use

```auto
wSession.session = `JSESSIONID=${msg.payload.result.sessionID}`

```

Note that you don't generally need semi-colons.

---

<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 May 2025 21:06 UTC](https://discourse.nodered.org/t/flow-set-parent-dynamic-name/96705/3 "2025-05-06T21:06:27Z")

</div>

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