# Sub-flows - help with their settings and getting information from them

**URL:** <https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884>\
**Category:** General\
**Created:** [3 January 2020 22:12 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884 "2020-01-03T22:12:35Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 January 2020 22:12 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/1 "2020-01-03T22:12:35Z")

</div>

Normally with `function` nodes, you can do a `node-warn("message")` and you see the `message` under the node.

Alas that isn't possible with `sub-flows`.  
Well, it kind of it - I believe.  
With the `status` button ticked.

But then I seem to be running into problems with multiple occurrences of said sub-flow and the messages.

What I've done to control which sub-flow's message I see is to put a bit of _login_ in the flow so I send a message `{payload:'ON',topic:'DEBUG'}` (where it can be `ON` or `OFF`.

That is a _gate_ (well: `gate`) before the output to the `status` output.

Here's the problem:  
I have (say) 8 of these nodes of the sub-flow. Each has its own `debug` input nodes.  
I turn on the debug for node 3 and I see node 7's debug information.

Keh? ☹🙄

---

<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:** [3 January 2020 22:18 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/2 "2020-01-03T22:18:37Z")

</div>

Without seeing the actual flow, it's hard to suggest where it may be going wrong.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 January 2020 22:26 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/3 "2020-01-03T22:26:25Z")

</div>

Yeah, I know.

Couple of problems:  
1 - it has _foreign_ nodes in it.  
2 - it (just the subflow) is way too big to post.

I shall try to create a few smaller ones which have the same problem.  
But I am sure _Mr Murphy_ will step in and stop that happening.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 January 2020 22:58 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/4 "2020-01-03T22:58:50Z")

</div>

Ok, I **may** have found the problem, but would like confirmation, because I have a habit of not getting it right.

1 - See `debug` injection nodes for sub-flow (#8).  
2 - See message from other sub-flow (#7)

 ![Screenshot from 2020-01-04 09-42-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/87b2857ed3308fb8ce18cf20a982b2c64b4e6abc.png)

1 - Output from Sub-flow #6

 ![Screenshot from 2020-01-04 09-42-08](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e212f8231fdd838c4a463b76e819967d99fea3bd.png)

1 - Output from sub-flow #5

 ![Screenshot from 2020-01-04 09-42-16](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/aade598f783b1009eb9a3a4802636bbf09d588f0.png)

1 - Output from Sub-flow #4

 ![Screenshot from 2020-01-04 09-42-20](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/dcb597d94b52e4a7294cedc311f44fa05447b271.png)

1 - Looking **inside** sub-flow  
2 - node name (temp).  
Code: `node.warn(msg.payload)`

 ![Screenshot from 2020-01-04 09-42-58](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/25ac3cd62e7c4e1425f398014dddfe50f97d3289.png)

1 - (Sill in sub-flow)  
2 - `catch-all` connected to `link` node.  
3 - (top one) going to a `gate` node then to a `debug` node3.  
4 - (bottom one) going to the _output_ called `status` from sub-flow

 ![Screenshot from 2020-01-04 09-49-15](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/fee2652d710122e311e41ed7e2c34d4eb41ab4ad.png)

1 - `gate` default to `closed`.  
So it shouldn't let messages through.  
But I think I am not getting how to get messages from a sub-flow  
I maybe need the `gate` between the `catch-all` and the `status` output node.

 ![Screenshot from 2020-01-04 09-43-16](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/85294fb5ad5814814490be1c521c7107cb17c91e.png)

Please confirm.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [3 January 2020 23:14 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/5 "2020-01-03T23:14:20Z")

</div>

I notice that in the debug you are displaying the messages from 'all nodes'. you might want to change it to curent flow

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 January 2020 23:19 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/6 "2020-01-03T23:19:22Z")

</div>

Yes, thanks @zenofmud, but then I have to go through setting all that up to check for certain things.

Then when I want to look back at the bigger picture........ I have to re-set which debug nodes to use. Then when I need to look at _those specific ones_ I need to set it again.

That seems too complicated.

I get that work needs to be done, but I am trying to keep it simple.

Sorry.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [3 January 2020 23:22 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/7 "2020-01-03T23:22:15Z")

</div>

> [@knolleary](#):
>
> ...Without seeing the actual flow

Well you did ask!!

@Trying_to_learn, can't you distill the issue into a more concise flow?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 January 2020 23:29 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/8 "2020-01-03T23:29:16Z")

</div>

I am kind of stuck between a rock and hard place.

I fully appreciate it is good to refine it down to a specific case - which makes it easier on which to work.

But (yeah, there's usually one of those) I have no idea what I am doing - kind of.

I am trying to get things done with the limited knowledge I have and not having a perfect vision of how it is all supposed to work.

Well, I kind of do, but getting it from there to a _complete_ picture and then to application is a whole other thing.

I (maybe) need a better understanding of how sub-flow output works.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [3 January 2020 23:41 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/9 "2020-01-03T23:41:09Z")

</div>

> [@Trying\_to\_learn](#):
>
> I am trying to get things done with the limited knowledge I have and not having a perfect vision of how it is all supposed to work.

Yes, I'm doing the same!  
...but I've found that by trying to isolate the issue by simplifying the flow, sometimes helps me by highlighting the problem, and certainly helps other members help me.

---

<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:** [3 January 2020 23:43 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/10 "2020-01-03T23:43:20Z")

</div>

So I can see you have a Function node doing a `node.warn()` inside the Subflow.  
Within that subflow you also have a `Catch` node that is wired via a `gate` node to a `status` output.

Are you expecting the `catch` node to handle the `node.warn()` message and prevent it appearing in the debug sidebar? If so, then that is not how it works. `node.warn()` writes a piece of text to the log - it does not send a message object.

The `catch` node handles errors - errors that are logged using `node.error("an error", msg)` - where, more specifically, the `msg` object you pass as the second argument to `node.error` is emitted from the `catch` node.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 January 2020 23:50 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/11 "2020-01-03T23:50:29Z")

</div>

@knolleary

Ok, this is the latest take on what I am doing in the sub-flow.

The idea is a `catch-all` node. That goes to a `switch` node which gets a `flow.DEBUG` value.  
If that is `ON` it passes the message.

```auto
[{"id":"80aeb895.49c29","type":"fan","z":"b1f30721.c3bde","x":4780,"y":1030,"wires":[[]]},{"id":"a00dc65a.1e50e8","type":"link in","z":"b1f30721.c3bde","name":"STATUS","links":["7cfe56fa.348198"],"x":4490,"y":1030,"wires":[["cc116178.c41e88"]],"l":true},{"id":"7cfe56fa.348198","type":"link out","z":"b1f30721.c3bde","name":"STATUS","links":["a00dc65a.1e50e8","b8e0924d.47d518","7e130ce.4d71cf4"],"x":4280,"y":1030,"wires":[],"l":true},{"id":"2ef78083.83a29","type":"catch","z":"b1f30721.c3bde","name":"","scope":null,"uncaught":false,"x":4070,"y":1030,"wires":[["7cfe56fa.348198"]]},{"id":"cc116178.c41e88","type":"switch","z":"b1f30721.c3bde","name":"DEBUG","property":"DEBUG","propertyType":"flow","rules":[{"t":"eq","v":"ON","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":4630,"y":1030,"wires":[["80aeb895.49c29"]]}]

```

Is that/this a better way of controlling what is seen?

The bigger idea is that I set a `flow.DEBUG` to `ON/OFF` and if it is `ON` it passes the message.

That then spits all the `node.warn( )` messages out the `status` of the sub-flow.  
But I am not sure I am fully getting that part.

(ITMT, I have discovered a great _work around_ for my seeming dependence of the `GATE` node.)

---

<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:** [3 January 2020 23:54 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/12 "2020-01-03T23:54:23Z")

</div>

> [@Trying\_to\_learn](#):
>
> That then spits all the `node.warn( )` messages out the `status` of the sub-flow.  
> But I am not sure I am fully getting that part.

You cannot control the `node.warn` messages. They _do not_ travel through the flow like normal messages - they are written straight to the log and sent to the Debug sidebar.

The Catch node only catches `node.error()` calls that have both a log message **and** a message object passed to it.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 January 2020 23:58 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/13 "2020-01-03T23:58:32Z")

</div>

Ah! Ok. So the `catch-all` only does errors.

Fair enough. That explains a lot.

So, what am I missing about in the sub-flow the `node.warn( )` and the `status node` output of the sub-flow?

Are the `node-warn( )` messages confined to the sub-flow and _exit_ via the `status node` output?

---

<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:** [4 January 2020 00:16 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/14 "2020-01-04T00:16:51Z")

</div>

> [@Trying\_to\_learn](#):
>
> Are the `node-warn( )` messages confined to the sub-flow and _exit_ via the `status node` output?

No. For the third time: `node.warn()` writes a log entry directly to node-red log and Debug sidebar. It is not a 'message' in the sense of the things passing along the wires in your flow. It is a piece of text written to the log.

The `status` output of the subflow has absolutely nothing to do with `node.warn` or the log or the Debug sidebar.

Let's step through what the `status` output is about.

First, lets consider a simple Function node in a normal flow - nothing to do with subflows. In that Function you can use the line `node.status("Hello")` and in the editor you will see the text `Hello` appear below the node:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0ed38454a7d655a98bfe4df4f6fd0ae92dfd0cd3.png)

This text is the Node Status. As you know, many nodes update their status to reflect some sort of internal state.

You can then add a `Status` node into the flow and it will get triggered whenever the Function node updates its status.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0779dd78a29d7c33db28b35b2432fd8a941977a5.png)

The message the Status node sends has the `msg.status` property set to an object containing the status text. It also includes `msg.status.source` which identifies which node set this status.

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

Now, if we put that single Function node into a Subflow and trigger it, lets see what we get:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/58ce1880823dadfd495f3914c8195e92f16ce637.png)

We _still_ get a message from the Status node, and it identifies its source as being a Function node, but the id is the internally generated id for the instance of the Function inside the subflow. There is nothing there to help us know it has come from the internals of the subflow. Also note the subflow instance node does not show any status text beneath it.

This is where the Status output of the subflow comes into play.

Lets change the Function inside the subflow to the following:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8e4826ac0c8d248e1fc67e1a0980f74a5e1496a2.png)

Rather than call `node.status` it now passes the message it a second output which is wired to the subflow's status output.

Now, when we trigger the subflow as before we get:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/983a0716290942fcedac130e6d2d3e00e15dd23f.png)

This time, notice the Subflow node shows the status text below it. Also note the source of the status message is identified as being the subflow instance.

* * *

I hope this shows the purpose of the status output of a subflow. It lets you create a subflow that updates its status property just as any node can.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [4 January 2020 00:29 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/15 "2020-01-04T00:29:03Z")

</div>

Ok, I sincerely apologise for the mix up.

I got `status` and `catch-all` mixed up.

My bad.

However, did you really look at the flow I posted? (No offence)

My take (though now modified. Though it shouldn't really change anything) is that in a sub-flow the `flow.BLAH` is local to that sub-flow.  
If that is wrong, well: all bets are off.

So I send a message into the sub-flow: `{payload:'ON',topic:'DEBUG'}`  
That goes into a `change` node which `flow.set(DEBUG), msg.payload`

The `function` nodes with their `node.warn( )` - which I now realise should be `node-status( )` are preceded by a `switch` node.

It looks at `flow.DEBUG`  
If it == `ON` then it passes on the message into the `function` node - with the `node.warn( )`  
So: (Big if) if `flow.DEBUG == 'OFF'` the message won't pass through.  
If it doesn't pass through, the `function` node won't get the message and so won't _warn_.

I'll modify it all now to `node.status( )`

Thanks. But could you confirm (even if not the accepted way) would that system work?  
(Stopping messages with `flow.DEBUG` isolating the `function` node.)

---

<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:** [4 January 2020 00:34 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/16 "2020-01-04T00:34:44Z")

</div>

> [@Trying\_to\_learn](#):
>
> However, did you really look at the flow I posted? (No offence)

Only enough to identify the misunderstanding you had with `node.warn` and then spent 10 minutes writing a long post to clarify it for you.

`flow.DEBUG` will be local to the subflow and using that to make a decision as to where messages should flow is a very sensible way of doing things.

> [@Trying\_to\_learn](#):
>
> I'll modify it all now to `node.status( )`

Is your goal to update the Status text under the Subflow node or to make things appear in the Debug sidebar? Changing everything to `node.status()` may not be what you really want to do. Note how in my post I didn't use `node.status()` in the final example inside the subflow?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [4 January 2020 00:42 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/17 "2020-01-04T00:42:46Z")

</div>

Well the main idea is (because I can't use `debug` nodes in a sub-flow) to have `node.warn( )` all over the place in the sub-flow that are controlled by `flow.DEBUG`.

I know I am putting the cart before the horse in how I am doing this, but as I need several iterations of the _code_ to see if works, I am having difficulty having it all on the same _page_, repeated _n_ times.

So in the sub-flow I have (now) a `switch` node that checks `flow.DEBUG == 'ON'` and if true, pass on the message.  
Then the payload is passed to a `function` node which: `node.warn(msg.payload)`

So if I inject a `DEBUG: ON` message all the `switch` nodes will allow the messages to get to the side bar and I can see what is what in the sub-flow.

When done, I inject a `DEBUG: OFF` and turn off all the debug nodes in the sub-flow.

Where I think I was getting confused was I wasn't consistent in how I did it. (I have suffered enough so I won't elaborate on that)

What you have told me helps me.

I **do** appreciate you taking the time, and would prefer I didn't need to ask. But I am not that smart - yet. (Probably never will be)

Thanks. I'll go over the code and fix up any stuff ups I have so it is consistent and also add some `node.status( )` things too to help with slower changing messages/states.

Again: Thanks.  
To you and all that replied.

---

<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:** [4 January 2020 00:47 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/18 "2020-01-04T00:47:12Z")

</div>

If this is about controlling what appears in the Debug sidebar then **do not use `node.status()`** because as I explained at length, `node.status()` has nothing to do with messages appearing in the Debug sidebar.

If this is all about controlling what appears in the Debug sidebar from inside the subflow, then your function node can do:

```auto
if (flow.get("DEBUG") == 'ON') {
   node.warn("Hi there");
}

```

There is no need to do much more than that.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [4 January 2020 00:50 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/19 "2020-01-04T00:50:17Z")

</div>

Yes, thanks.

I need (well.....) to use `node.status( )` because the _status_ of the sub-flow will change from time to time.  
That would be nice to see/know below the node.  
So that will be used correctly (I hope) so when a message comes in to _change the status of the sub flow_, it will print the correct information below said node.

Oh, on what you said, yes, I also agree.  
Though I would use the `msg.payload` so I can see what is being seen in the flow to track down why things aren't working.

Though I also admit that I am using a `switch` node and a `function` node to display the `node.warn( )` part.

I guess if I am using a `function` node then the extra `if( )` would be better. It is I have just been _bitten_ by understanding a _better_ use of the `switch` node.

(I may actually do what you said. Thanks.)

---

<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:** [4 January 2020 00:53 UTC](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884/20 "2020-01-04T00:53:47Z")

</div>

> [@Trying\_to\_learn](#):
>
> I need (well.....) to use `node.status( )` because the _status_ of the sub-flow will change from time to time.

Please read through my long explanation of `node.status()` again. In particular, again, note how I **don't** use `node.status()` in the final example of actually updating the subflow status.

If you want to update the status of a Subflow, you need to pass a message to the subflow's status output. You don't use `node.status()` to do that.

[Next page](https://discourse.nodered.org/t/sub-flows-help-with-their-settings-and-getting-information-from-them/19884.md?page=2)
