# Can I access the name of a subflow within a function node inside the subflow

**URL:** <https://discourse.nodered.org/t/can-i-access-the-name-of-a-subflow-within-a-function-node-inside-the-subflow/29651>\
**Category:** General\
**Created:** [7 July 2020 12:13 UTC](https://discourse.nodered.org/t/can-i-access-the-name-of-a-subflow-within-a-function-node-inside-the-subflow/29651 "2020-07-07T12:13:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [7 July 2020 12:13 UTC](https://discourse.nodered.org/t/can-i-access-the-name-of-a-subflow-within-a-function-node-inside-the-subflow/29651/1 "2020-07-07T12:13:44Z")

</div>

...so I can just use the name of subflow as an easy means of getting a parameter into the subflow?

---

<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:** [7 July 2020 12:20 UTC](https://discourse.nodered.org/t/can-i-access-the-name-of-a-subflow-within-a-function-node-inside-the-subflow/29651/2 "2020-07-07T12:20:29Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [7 July 2020 12:58 UTC](https://discourse.nodered.org/t/can-i-access-the-name-of-a-subflow-within-a-function-node-inside-the-subflow/29651/3 "2020-07-07T12:58:39Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/8/08e25517d6bc648799ed0336f1861764ae1d9727.jpeg)

---

<div class="post-metadata">

**Author:** ![michaelblight](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/michaelblight/32/445_2.png) [@michaelblight](https://discourse.nodered.org/u/michaelblight)\
**Post date:** [8 July 2020 04:27 UTC](https://discourse.nodered.org/t/can-i-access-the-name-of-a-subflow-within-a-function-node-inside-the-subflow/29651/4 "2020-07-08T04:27:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [8 July 2020 07:08 UTC](https://discourse.nodered.org/t/can-i-access-the-name-of-a-subflow-within-a-function-node-inside-the-subflow/29651/5 "2020-07-08T07:08:12Z")

</div>

> 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 ?

 ![Screenshot 2020-07-08 at 09.07.47](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f6ae2701b09864cee32621fa11eaf3cb7cf39534.jpeg)

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [8 July 2020 07:22 UTC](https://discourse.nodered.org/t/can-i-access-the-name-of-a-subflow-within-a-function-node-inside-the-subflow/29651/6 "2020-07-08T07:22:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [8 July 2020 07:35 UTC](https://discourse.nodered.org/t/can-i-access-the-name-of-a-subflow-within-a-function-node-inside-the-subflow/29651/7 "2020-07-08T07:35:40Z")

</div>

> Because this is pretty much the first time I'm coming to using subflows

Got it 🙂

```auto
[{"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.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [8 July 2020 07:56 UTC](https://discourse.nodered.org/t/can-i-access-the-name-of-a-subflow-within-a-function-node-inside-the-subflow/29651/9 "2020-07-08T07:56:42Z")

</div>

Got it (I think) 😀

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/ca1ba16a13ec8b7fd60e7c5440eb51a64537ee3e.png)

[edit]

Really got it now 🙂  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/ed110cb464960d56c3c95abda005fc573e5e5599.png)

[/edit]

[edit]  
No \_ i don;t think I've quite got it yet when trying out in my subflow ☹

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9d0e48eff396882680f75b33bb0562a1efffbcd1.jpeg)  
[/edit]

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [8 July 2020 12:10 UTC](https://discourse.nodered.org/t/can-i-access-the-name-of-a-subflow-within-a-function-node-inside-the-subflow/29651/10 "2020-07-08T12:10:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [8 July 2020 21:43 UTC](https://discourse.nodered.org/t/can-i-access-the-name-of-a-subflow-within-a-function-node-inside-the-subflow/29651/11 "2020-07-08T21:43:25Z")

</div>

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 🙂

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/d/1d36ed5f80c8b53b1effa3c34936117981457194.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/678f710a25c25976df75d2362e86602f98a6dc1c.png)

🙂

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [22 July 2020 21:43 UTC](https://discourse.nodered.org/t/can-i-access-the-name-of-a-subflow-within-a-function-node-inside-the-subflow/29651/12 "2020-07-22T21:43:33Z")

</div>

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