# Accessing global variables in subflow?

**URL:** <https://discourse.nodered.org/t/accessing-global-variables-in-subflow/78812>\
**Category:** General\
**Created:** [30 May 2023 10:16 UTC](https://discourse.nodered.org/t/accessing-global-variables-in-subflow/78812 "2023-05-30T10:16:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nico25](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@nico25](https://discourse.nodered.org/u/nico25)\
**Post date:** [30 May 2023 10:16 UTC](https://discourse.nodered.org/t/accessing-global-variables-in-subflow/78812/1 "2023-05-30T10:16:38Z")

</div>

After some research I found out, that you can access the parents flows variables in a subflow by using environmental variables in the subflow. Is that also possible for global variables?  
Background:  
I want to implement an alarms-system. These alarms can be triggered in different flows, so I save the alarm states for each alarm globally in an array.  
Why the sublow?- Wanted to make the flow look cleaner- no technical background.

---

<div class="post-metadata">

**Author:** ![kevinGodell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kevingodell/32/27040_2.png) [@kevinGodell](https://discourse.nodered.org/u/kevinGodell)\
**Post date:** [31 May 2023 02:04 UTC](https://discourse.nodered.org/t/accessing-global-variables-in-subflow/78812/2 "2023-05-31T02:04:53Z")

</div>

I just tested by setting a global var in a function node that **is not in a subflow** and was able to successfully access it from another function node that **is in a subflow**. It seems that `global.set` and `global.get` are not limited by being in a subflow.

---

<div class="post-metadata">

**Author:** ![nico25](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@nico25](https://discourse.nodered.org/u/nico25)\
**Post date:** [31 May 2023 08:45 UTC](https://discourse.nodered.org/t/accessing-global-variables-in-subflow/78812/3 "2023-05-31T08:45:13Z")

</div>

I guess I was overthinking the topic, should´ve tested first before posting 😅

---

<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:** [14 June 2023 08:45 UTC](https://discourse.nodered.org/t/accessing-global-variables-in-subflow/78812/4 "2023-06-14T08:45:39Z")

</div>

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