...so I can just use the name of subflow as an easy means of getting a parameter into the subflow?
No you cannot.
This gets asked quite often, so something we're aware of as a general requirement to consider what other things could/should be exposed to the Function node (or more widely as environment variables that can be accessed by jsonata/change node etc)
Ta for info
I'll work around by sticking a pre-process function node before the subflow and add its name as a property to the msg
This looks like an opportunity for a wish list: knowing the node-id of the subflow instance from within the subflow would be very helpful for traceability. Something like a call stack trace.
EDIT: Actually I just noticed that this has been improved with 1.1.0 over 1.0.0, so maybe it's already possible somehow. Debug nodes within a subflow now include a link back to the subflow instance. I don't recall reading this in the release notes, but it's very helpful.
I'll work around by sticking a pre-process function node before the subflow and add its name as a property to the msg
Why not add a "name" field to the ui of the subflow and use that instead ?
Because this is pretty much the first time I'm coming to using subflows
Can you export what you've done please, as I can't replicate getting subflow_name into the message
Because this is pretty much the first time I'm coming to using subflows
Got it
[{"id":"e35fa59e.d3186","type":"subflow","name":"Subflow 1","info":"","category":"","in":[{"x":92,"y":72,"wires":[{"id":"33a5823f.6b27ee"}]}],"out":[{"x":308,"y":72,"wires":[{"id":"33a5823f.6b27ee","port":0}]}],"env":[{"name":"name","type":"str","value":"","ui":{"label":{"en-US":"Name"},"type":"input","opts":{"types":["str"]}}}],"color":"#DDAA99"},{"id":"33a5823f.6b27ee","type":"function","z":"e35fa59e.d3186","name":"","func":"\nmsg.subflow_name = env.get(\"name\")\n\nreturn msg","outputs":1,"noerr":0,"x":194,"y":72,"wires":[[]]},{"id":"f20826aa.21034","type":"subflow:e35fa59e.d3186","z":"d971d6c8.294f9","name":"","env":[{"name":"name","value":"subflow with some name","type":"str"}],"x":444,"y":192,"wires":[["a0b9dd89.fe22"]]},{"id":"da2760ce.713518","type":"inject","z":"d971d6c8.294f9","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":276,"y":192,"wires":[["f20826aa.21034"]]},{"id":"a0b9dd89.fe22","type":"debug","z":"d971d6c8.294f9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":616,"y":192,"wires":[]}]
Check the function node in the subflow - it reads the environment variable. Also check the properties of the subflow, which is where you can configure the input elements - this is quite powerful for reusable subflows with their own properties.
Got it (I think)
[edit]
Really got it now
[/edit]
[edit]
No _ i don;t think I've quite got it yet when trying out in my subflow
[/edit]
I'm getting strange behaviour when I try and add this method into my existing 1.1.0 subflow
But, like I say - I'm new to subflows so I need to start from the beginning again
So I'm going to a small test on an existing 1.0.6 install and see if that works OK
Then try another 1.1.0 machine and see what happens there
Ok - created a subflow on a 1.0.3 instance and everthing worked smoothly and as expected and I've got my logging subflow working fine using a env value as its parameter as to what topic to set in an MQTT logging message
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.