# Is there a way to allow for the msg. / flow. / global. input types for subflows?

**URL:** <https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530>\
**Category:** Developing Nodes\
**Created:** [13 August 2020 13:52 UTC](https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530 "2020-08-13T13:52:33Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrRosenkilde](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MrRosenkilde](https://discourse.nodered.org/u/MrRosenkilde)\
**Post date:** [13 August 2020 13:52 UTC](https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530/1 "2020-08-13T13:52:33Z")

</div>

Hi, a lot of nodes has the functionality of reading from a context on inputs.  
For example the change node can read a variable from the global context and write it to the incoming message  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/a/3a70e53f849ac2489a0eee1b73829b3d2a5c975d.png)

I would very much like to have the same feature in my own subflows, so that something like this subflow with a single environment variable called input, could be set to msg.payload:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7a3064da62366f610f65c00f97ef368bccb2d294.png)

Is there any way to enable that functionality in subflows?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [13 August 2020 14:14 UTC](https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530/2 "2020-08-13T14:14:53Z")

</div>

No, that is not possible.

The subflow flow properties appear as environment variables to the nodes within the flow. Their values are determined when the flow starts and cannot change without a restart.

That means they cannot be set via message or context properties.

---

<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:** [13 August 2020 14:21 UTC](https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530/3 "2020-08-13T14:21:13Z")

</div>

Hi @MrRosenkilde, as Nick has stated, by design this is not possible with subflows. I use another node that gives you _subroutine_ like functionality where you can pass values in via `msg`, `flow`, `global` etc. I provided some feedback [here](https://discourse.nodered.org/t/thoughts-on-this-new-node-node-red-contrib-components/30279/7) when another user raised a question on its usefulness.

Its not quite a subflow but perhaps it will work for your current requirement?

---

<div class="post-metadata">

**Author:** ![MrRosenkilde](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MrRosenkilde](https://discourse.nodered.org/u/MrRosenkilde)\
**Post date:** [18 August 2020 07:48 UTC](https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530/4 "2020-08-18T07:48:13Z")

</div>

Thanks for the answer.

Do you know if there's any plans for changing/improving that aspect of the language?

Is there a place where i can put in a feature request?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [18 August 2020 08:09 UTC](https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530/5 "2020-08-18T08:09:58Z")

</div>

> [@MrRosenkilde](#):
>
> Do you know if there's any plans for changing/improving that aspect of the language?

No, this is not something that is going to change.

Nodes know nothing about env vars - it is the runtime that evaluates them and gives the node its configuration values with the env var values already substituted. That only works when the node is first started and it is given its configuration. If the values change, then the only way the node knows this is if it is completely restarted.

---

<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:** [18 August 2020 08:28 UTC](https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530/6 "2020-08-18T08:28:58Z")

</div>

An alternative approach is to send the subflow a message passing it the relevant information, but I assume you know that already.

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [18 August 2020 09:12 UTC](https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530/7 "2020-08-18T09:12:01Z")

</div>

The alternative would also be node-red-contrib-components (look at [Renaming of node-red-contrib-components](https://discourse.nodered.org/t/renaming-of-node-red-contrib-components/31649/2))  
It does "kind of" what subflows can do but with this extra possibility.  
GV

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [18 August 2020 11:08 UTC](https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530/8 "2020-08-18T11:08:07Z")

</div>

> [@greengolfer](#):
>
> t does "kind of" what subflows can do but with this extra possibility.  
> GV

It does offer some different capabilities, but it does _not_ allow arbitrary changing of a node's configuration through msg/context properties.

---

<div class="post-metadata">

**Author:** ![MrRosenkilde](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MrRosenkilde](https://discourse.nodered.org/u/MrRosenkilde)\
**Post date:** [19 August 2020 06:48 UTC](https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530/9 "2020-08-19T06:48:06Z")

</div>

> No, this is not something that is going to change.
> 
> Nodes know nothing about env vars - it is the runtime that evaluates them and gives the node its configuration values with the env var values already substituted. That only works when the node is first started and it is given its configuration. If the values change, then the only way the node knows this is if it is completely restarted.

Thanks again for the quick and concise answer 🙂

One last question, if i may, given the information, it sounds impossible to build something like the  
node-red-contrib-loop-processing palette ([node-red-contrib-loop-processing (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-loop-processing)) which has node configurations that can't be made with subflows.

If i wanted to build something more complex, like those nodes, it's now my understanding that that is impossible with subflows, but then how are they made? And if i wanted to do it myself, how would i get started on it?  
(Not looking for you to explain it to me in details, just a pointer to where/how i can get started on learning the process)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [19 August 2020 07:02 UTC](https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530/10 "2020-08-19T07:02:11Z")

</div>

> [@MrRosenkilde](#):
>
> If i wanted to build something more complex, like those nodes, it's now my understanding that that is impossible with subflows,

Why do you say it is impossible?

You can certainly create a subflow that loops over some property. If you want to use a context value to help dynamically set the loop condition for a given message, then you copy that context property onto the message before passing it in.

---

<div class="post-metadata">

**Author:** ![MrRosenkilde](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MrRosenkilde](https://discourse.nodered.org/u/MrRosenkilde)\
**Post date:** [19 August 2020 08:47 UTC](https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530/11 "2020-08-19T08:47:21Z")

</div>

Yes, it is definitely possible to replicate the functionality.

What i was referring to is the UI:

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

I'm asking these questions not to solve a single use case (like looping over a property), but because i have been tasked with building a library that other developers can use to expand on the platform that my company is currently working on.

I guess what i'm trying to ask is: If it's not possible to implement a feature like setting environment variables to something like msg.payload with subflows, or implement all these other cool features that i see in custom nodes, then how do all these nodes that i'm using have that functionality, and if i wanted to build a node myself that had some of that cool functionality, how would i go about doing that?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [19 August 2020 10:43 UTC](https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530/12 "2020-08-19T10:43:57Z")

</div>

The guide for creating new nodes is here: [https://nodered.org/docs/creating-nodes/](https://nodered.org/docs/creating-nodes/)

---

<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:** [2 September 2020 10:44 UTC](https://discourse.nodered.org/t/is-there-a-way-to-allow-for-the-msg-flow-global-input-types-for-subflows/31530/13 "2020-09-02T10:44:13Z")

</div>

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