# Subflow and subflow in a subflow and context

**URL:** <https://discourse.nodered.org/t/subflow-and-subflow-in-a-subflow-and-context/98993>\
**Category:** General\
**Tags:** subflow, dashboard-2, context\
**Created:** [9 September 2025 07:32 UTC](https://discourse.nodered.org/t/subflow-and-subflow-in-a-subflow-and-context/98993 "2025-09-09T07:32:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rewegit](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rewegit/32/4778_2.png) [@rewegit](https://discourse.nodered.org/u/rewegit)\
**Post date:** [9 September 2025 07:32 UTC](https://discourse.nodered.org/t/subflow-and-subflow-in-a-subflow-and-context/98993/1 "2025-09-09T07:32:56Z")

</div>

While learning DB2, I have come to appreciate the use of subflows. The only thing that gives me headaches is dealing with the context.

According to [Working with context : Node-RED](https://nodered.org/docs/user-guide/context), I can use, for example,

`var color = flow.get(“$parent.color”);`

That helps a lot. For more complex sites, I like to use subflows within subflows... but I can't get anywhere with a `$parent`.

Is there any way to access a common context across multiple levels? So that the sub-subflows can access the context of the top-level subflow, so to speak?

Something like `$prent.$parent.var` Or is there another way? Would that be possible, for example, via an external library with the Context API?

I already work with my own library, which allows a clean separation by context and namespaces over a maximum of 2 levels ($parent). I configure the context and namespace of the SF with env variables in the SF.

---

<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:** [9 September 2025 08:20 UTC](https://discourse.nodered.org/t/subflow-and-subflow-in-a-subflow-and-context/98993/2 "2025-09-09T08:20:34Z")

</div>

Have you tried it with $parent.$parent?

---

<div class="post-metadata">

**Author:** ![rewegit](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rewegit/32/4778_2.png) [@rewegit](https://discourse.nodered.org/u/rewegit)\
**Post date:** [9 September 2025 09:53 UTC](https://discourse.nodered.org/t/subflow-and-subflow-in-a-subflow-and-context/98993/3 "2025-09-09T09:53:16Z")

</div>

Now I'm totally perplexed.  
I've just tested a simple scenario: a subflow in a subflow in a subflow, and it works perfectly with $parent.$parent.$parent.  
Now I just need to figure out what's going wrong in my large flow.  
Thanks.

---

<div class="post-metadata">

**Author:** ![ThingsTinkerer](https://avatars.discourse-cdn.com/v4/letter/t/91b2a8/32.png) [@ThingsTinkerer](https://discourse.nodered.org/u/ThingsTinkerer)\
**Post date:** [9 September 2025 10:23 UTC](https://discourse.nodered.org/t/subflow-and-subflow-in-a-subflow-and-context/98993/4 "2025-09-09T10:23:24Z")

</div>

Before I knew about `env.get("NR_FLOW_NAME")` I defined it in each flow’s env and passed it on in every subflow. The easiest way I found to do that was to define the same variable in each subflow as env variable and call `$parent` there (once) every time. For example:

- flow (top level): env flowName = “flow name”
  - subflow (level 1): env flowName = $parent.flowName
    - subflow (level 2): env flowName = $parent.flowName
      - … and so forth

It was a good way to not worry about levels (ie. $parent.$parent.$par…) and simple enough because I only needed one variable and needed it almost everywhere for logging purposes. So depends on your usage. If you have many values or don’t need them most of the time, it will be more of a hassle.

Alternatively use global context.

---

<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:** [23 September 2025 10:24 UTC](https://discourse.nodered.org/t/subflow-and-subflow-in-a-subflow-and-context/98993/5 "2025-09-23T10:24:22Z")

</div>

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