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
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:
Is there any way to enable that functionality in subflows?
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?
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.
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
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) 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)
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.
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?