# Subflows do not allow for context variables to be used when setting properties. Why?

**URL:** <https://discourse.nodered.org/t/subflows-do-not-allow-for-context-variables-to-be-used-when-setting-properties-why/97902>\
**Category:** Developing Nodes\
**Tags:** subflow\
**Created:** [1 July 2025 17:56 UTC](https://discourse.nodered.org/t/subflows-do-not-allow-for-context-variables-to-be-used-when-setting-properties-why/97902 "2025-07-01T17:56:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mecworks](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mecworks/32/101359_2.png) [@Mecworks](https://discourse.nodered.org/u/Mecworks)\
**Post date:** [1 July 2025 17:56 UTC](https://discourse.nodered.org/t/subflows-do-not-allow-for-context-variables-to-be-used-when-setting-properties-why/97902/1 "2025-07-01T17:56:11Z")

</div>

When creating a subflow and editing the properties, you can configure the type of input it can have. The choices are Input, credential, select, checkbox and spinner config node. So, I select Input as the type.

 ![Subflow Properties](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/3/a36ff44cb55784e6b87b6d43c05c214fbba782c3.jpeg)

However, when using the subflow, I want to populate the value using a context variable, the choices for input are only string, number, boolean, JSON, buffer and envi\_variable.

 ![Setting Subflow Properties](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/8785a64bc85579a83ba29b5cd57e38bf47a32434.jpeg)  
Why are context (flow and global) available as choices? What this means is that I need to go through the extra step of placing a change node before calling this subflow, just to retreive the global or flow value and set an environment variable. I should be able to just be able to use the glowbal or flow values directly. Am I missing something?

Ideally, when using a subflow, you should be able to use context values and jsonata expressions in addition to the other input types.

Is there a way to do this? Am I just missing something?

---

<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:** [1 July 2025 18:25 UTC](https://discourse.nodered.org/t/subflows-do-not-allow-for-context-variables-to-be-used-when-setting-properties-why/97902/2 "2025-07-01T18:25:18Z")

</div>

> [@Mecworks](#):
>
> just to retreive the global or flow value and set an environment variable

You can't do that either, environment variables are constants.

Subflow properties are constants, if you want to pass in variable data then you must do it using message properties.

---

<div class="post-metadata">

**Author:** ![Mecworks](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mecworks/32/101359_2.png) [@Mecworks](https://discourse.nodered.org/u/Mecworks)\
**Post date:** [2 July 2025 01:03 UTC](https://discourse.nodered.org/t/subflows-do-not-allow-for-context-variables-to-be-used-when-setting-properties-why/97902/3 "2025-07-02T01:03:08Z")

</div>

OK, that makes more sense on how things work _now_. I hope that this can change in the future. It would be nice to be able to use context variables and Jsonata inside a subflow via the settings page for the subflow.

It's just that if you only need one value passed in as a message property, you might as well have everything configured that way and forego any properties as you don't want to split the methods for setting data in the node. It would be confusing to have to set some properties in the properties page and send others in as a message property.

It would be much cleaner to add context and Jsonata expression support to the options page. Then everything you need could be set there.

I am wondering if you can set environment variables using a function node rather than a change node from outside the subflow. It looks like Node.js supports this with a `process.env.MY_VARIABLE = 'my_value'` call. This would only work if NodeRed reads environment variables at the time of use rather than at initialization. Otherwise it won't work.

I'll test this out but for now, I think I'll have to switch entirely over to passing in configuration options as flow properties and not use the properties page at all.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [2 July 2025 01:30 UTC](https://discourse.nodered.org/t/subflows-do-not-allow-for-context-variables-to-be-used-when-setting-properties-why/97902/4 "2025-07-02T01:30:34Z")

</div>

> [@Mecworks](#):
>
> This would only work if NodeRed reads environment variables at the time of use rather than at initialization. Otherwise it won't work

You answered your own question 😉  
These are for fixed values, set when that particular subflow instance is deployed.

You can still access flow/global variables from **within** the subflow however.

---

<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:** [2 July 2025 07:56 UTC](https://discourse.nodered.org/t/subflows-do-not-allow-for-context-variables-to-be-used-when-setting-properties-why/97902/5 "2025-07-02T07:56:03Z")

</div>

If you want to use different context variable names for each instance of the subflow then you can pass in the context variable name as a string and then use that when you get the variable in the subflow.

---

<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:** [31 August 2025 07:56 UTC](https://discourse.nodered.org/t/subflows-do-not-allow-for-context-variables-to-be-used-when-setting-properties-why/97902/6 "2025-08-31T07:56:47Z")

</div>

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