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

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

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

Is there any way to enable that functionality in subflows?

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.

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 when another user raised a question on its usefulness.

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

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?

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.

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

The alternative would also be node-red-contrib-components (look at Renaming of node-red-contrib-components)
It 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.

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 :slight_smile:

One last question, if i may, given the information, it sounds impossible to build something like the
node-red-contrib-loop-processing palette (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)

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.

Yes, it is definitely possible to replicate the functionality.

What i was referring to is the UI:

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?

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

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