# Constructing flow, subflow, and group global variables from user global variables

**URL:** <https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316>\
**Category:** General\
**Created:** [11 October 2024 13:13 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316 "2024-10-11T13:13:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![phreed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/phreed/32/95321_2.png) [@phreed](https://discourse.nodered.org/u/phreed)\
**Post date:** [11 October 2024 13:13 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/1 "2024-10-11T13:13:25Z")

</div>

User global environment variables are new, since v3.1

- [Using environment variables : Node-RED](https://nodered.org/docs/user-guide/environment-variables#global-environment-variables)
- [Version 3.1 released : Node-RED](https://nodered.org/blog/2023/09/06/version-3-1-released#global-environment-variables)

What I want to know is if, for example, a flow global variable can be set based on a user global variable?  
And if so, what is the grammar for doing so?

---

<div class="post-metadata">

**Author:** ![phreed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/phreed/32/95321_2.png) [@phreed](https://discourse.nodered.org/u/phreed)\
**Post date:** [11 October 2024 13:16 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/2 "2024-10-11T13:16:00Z")

</div>

I am asking the question because:

### Changes to how Environment Variables are evaluated

"Because of the need to make JSONata fully asynchronous in the future,  
we’ve changed how the env var evaluation is done -  
their values are now all **generated when the flows start and not re-evaluated again**."

---

<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:** [11 October 2024 13:59 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/3 "2024-10-11T13:59:10Z")

</div>

Hi, welcome to the forum.

Unfortunately your question is not making a whole lot of sense (to me).

Perhaps some annotated screenshots would help me understand what you are attempting to do (and perhaps there is a better way)

---

<div class="post-metadata">

**Author:** ![phreed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/phreed/32/95321_2.png) [@phreed](https://discourse.nodered.org/u/phreed)\
**Post date:** [11 October 2024 14:58 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/4 "2024-10-11T14:58:25Z")

</div>

Sure,  
Suppose you have set a bunch of user level global variables.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9c0659204041a1dce01b83de7bc3187f11c9fbdd.png)

I also have some flow(tab) level global variables:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/b/5ba4f37ace541fb8f8b59459dd7225b7515e47ca.png)

In the two images the variables are duplicated.  
Is there a way to use the user level variables to provide values to the global variables defined in a config node in the flow(tab)?

I am probably not asking this very well and I do not fully understand what a global and flow(tab?) variable defined in a config node are and how that flow(tab) global variable differs (if at all) from one defined at the user level.

Something like:

```auto
Property : global. FTH_FTS_URL_MAP
Value : str. ${FTH_FTS_URL}

```

---

<div class="post-metadata">

**Author:** ![phreed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/phreed/32/95321_2.png) [@phreed](https://discourse.nodered.org/u/phreed)\
**Post date:** [11 October 2024 15:13 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/5 "2024-10-11T15:13:59Z")

</div>

I currently have a node on each tab defining the same global variables.  
I assumed the global variables were global to the specific tab.  
Is that wrong?

---

<div class="post-metadata">

**Author:** ![phreed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/phreed/32/95321_2.png) [@phreed](https://discourse.nodered.org/u/phreed)\
**Post date:** [11 October 2024 15:33 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/6 "2024-10-11T15:33:56Z")

</div>

I think I am wrong.  
After reading the documentation it seems like I will end up with indeterminate behaviour.

Would the following syntax work?

```auto
Property : flow. FTH_FTS_URL_MAP
Value : str. ${FTH_FTS_URL}

```

---

<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:** [11 October 2024 15:42 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/7 "2024-10-11T15:42:56Z")

</div>

> [@phreed](#):
>
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/b/5ba4f37ace541fb8f8b59459dd7225b7515e47ca.png)

What node is ↑ this?

  

> [@phreed](#):
>
> Something like:
> 
> ```auto
> Property : global. FTH_FTS_URL_MAP
> Value : str. ${FTH_FTS_URL}
> 
> ```

you can use ENV VARs in most fields using `${ENV_VAR_NAME}` but they are not re-writtable is thats what you are asking?

you can also use a change node to SET `global.something` to the value of `env.something`

* * *

Some clarification:

ENV VARs are fixed. Cannot be changed at runtime, ENV VARS can come from the OS or configured in Node-RED

Global and Flow are context and can be read/write and any time, at runtime.

* * *

Here is some reading and watching that should help:

#### Videos

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

#### Env Var docs

> **[Using environment variables : Node-RED](https://nodered.org/docs/user-guide/environment-variables)**

---

<div class="post-metadata">

**Author:** ![phreed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/phreed/32/95321_2.png) [@phreed](https://discourse.nodered.org/u/phreed)\
**Post date:** [11 October 2024 16:20 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/8 "2024-10-11T16:20:55Z")

</div>

The node "Edit config node" is this one, a config node:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/876f4f6dcf0cc42513c95ecf03d18366c239cebf.png)

I will watch the videos and read the link you sent.

---

<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:** [11 October 2024 16:31 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/9 "2024-10-11T16:31:51Z")

</div>

that is NOT a node-red node. It is a contib / add in node. thats partly why i was confused by your questions.

Typically, if you want to use an ENV VAR, you select `Env` from the drop down OR, if its got an `Env` dropdown, you use `$(ENV_VAR_NAME)`

This node (whatever it is) was likely added to simplify either Env or Context but unless i know which one it is, i have no idea if it is talking about context, env vars or some other made up type of variable storage.

---

<div class="post-metadata">

**Author:** ![phreed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/phreed/32/95321_2.png) [@phreed](https://discourse.nodered.org/u/phreed)\
**Post date:** [14 October 2024 19:17 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/11 "2024-10-14T19:17:15Z")

</div>

I have been able to programmatically load flows in ansible with:

```yaml
uri:
        url: "http://{{ noderedserver_ipv4 }}:{{ noderedserver_port }}/flow"
        method: POST
        headers:
          Content-Type: application/json
          Node-RED-API-Version: v1
          Node-RED-Deployment-Type: full
          Authorization: Bearer {{ nodered_admin_token }}
        body: "{{ lookup('file', playbook_dir + '/FreeTAKHub-Webmap/freetakhub_config.json') }}"
        body_format: json
        status_code: 200

```

This simulates the the "Import" function.  
What is the recommended way to initialize the global variables?

---

<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:** [14 October 2024 19:25 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/12 "2024-10-14T19:25:03Z")

</div>

> [@phreed](#):
>
> What is the recommended way to initialize the global variables?

Possibly the [reload option](https://nodered.org/docs/api/admin/methods/post/flows/)? (for memory based context)

Failing that, include a flow with a callable endpoint  
http-in -\> function (iterate and reset context) -\> http-response

---

<div class="post-metadata">

**Author:** ![phreed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/phreed/32/95321_2.png) [@phreed](https://discourse.nodered.org/u/phreed)\
**Post date:** [14 October 2024 19:28 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/13 "2024-10-14T19:28:38Z")

</div>

Could they be set in `https://nodered.org/docs/user-guide/runtime/settings-file` before starting node-red?

```json
...
   exportGlobalContextKeys: true,
...
    functionGlobalContext: {
        FTH_FTS_URL = "127.0.0.1",
        FTH_FTS_TCP_Port = "8087"
    },
...

```

---

<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:** [14 October 2024 19:31 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/14 "2024-10-14T19:31:41Z")

</div>

no. settings are loaded first (before context)

You may need to create a plugin node or go with the flows option.

PS, did you try the reload?

---

<div class="post-metadata">

**Author:** ![phreed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/phreed/32/95321_2.png) [@phreed](https://discourse.nodered.org/u/phreed)\
**Post date:** [14 October 2024 20:00 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/15 "2024-10-14T20:00:19Z")

</div>

This suggests I can overwrite the global flow:  
[Put Flow Node : Global](https://nodered.org/docs/api/admin/methods/put/flow/)

However when I look at the exported flow, I do not see a node with "global" id.  
What is see is the following:

```json
{
  "id": "3f81c31d1e0b6231",
  "type": "global-config",
  "name": "global-config",
  "env": [
            {
                "name": "FTH_FTS_URL",
                "value": "127.0.0.1",
                "type": "str"
            },
            {
                "name": "FTH_FTS_TCP_Port",
                "value": "8087",
                "type": "str"
            }
   ]
}

```

---

<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:** [14 October 2024 20:09 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/16 "2024-10-14T20:09:30Z")

</div>

In terms of flows, "global" is refering to global things like context nodes.

To clarify - what are you actually trying to do? Are you attempting to reset global context? Global environment variables? Global flows nodes?

---

<div class="post-metadata">

**Author:** ![phreed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/phreed/32/95321_2.png) [@phreed](https://discourse.nodered.org/u/phreed)\
**Post date:** [14 October 2024 20:21 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/17 "2024-10-14T20:21:35Z")

</div>

Global environment variables.  
(In case it was not obvious, I inherited this project and am just learning NodeRed.)

---

<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:** [14 October 2024 20:49 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/18 "2024-10-14T20:49:11Z")

</div>

> [@phreed](#):
>
> Global environment variables

Which ones? Those set in the main menu or those set by the launching environment? Those set in flow tab? Those set in a subflow? All of them?

Also, are 100% certain you mean environment variables and not global content?

Perhaps a little learning would clarify matters.

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![phreed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/phreed/32/95321_2.png) [@phreed](https://discourse.nodered.org/u/phreed)\
**Post date:** [14 October 2024 21:15 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/19 "2024-10-14T21:15:31Z")

</div>

Yes I watched all the videos (when you mentioned this before).  
I am going through them again working all the examples.  
I probably mean "global context".

But when the dialog is clearly labeled "Global Environment Variables" it makes one think that they are global environment variables:

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/7/f724213f38ecb619834f5b6c1aaf73fd49a0fcff.png)

---

<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:** [14 October 2024 22:08 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/20 "2024-10-14T22:08:29Z")

</div>

Ok, so I'm pretty sure those particular values are stored in the flow JSON. If you want to clear them you would need to manipulate the JSON before issuing the POST to /flows

---

<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:** [15 October 2024 14:21 UTC](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316/21 "2024-10-15T14:21:07Z")

</div>

> [@phreed](#):
>
> But when the dialog is clearly labeled "Global Environment Variables" it makes one think that they are global environment variables:

They are environment variables. The cannot be modified at run time.

[Next page](https://discourse.nodered.org/t/constructing-flow-subflow-and-group-global-variables-from-user-global-variables/92316.md?page=2)
