# Quo Vadis: Function nodes with multible outputs

**URL:** <https://discourse.nodered.org/t/quo-vadis-function-nodes-with-multible-outputs/47681>\
**Category:** General\
**Created:** [25 June 2021 20:56 UTC](https://discourse.nodered.org/t/quo-vadis-function-nodes-with-multible-outputs/47681 "2021-06-25T20:56:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![RonMa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ronma/32/42531_2.png) [@RonMa](https://discourse.nodered.org/u/RonMa)\
**Post date:** [25 June 2021 20:56 UTC](https://discourse.nodered.org/t/quo-vadis-function-nodes-with-multible-outputs/47681/1 "2021-06-25T20:56:45Z")

</div>

Hi guys,

again probably a really simple question, but, again, I can´t figure it how somehow 🙄

Here is what I want to accomplish. I have a function node which is triggered when my outdoor light sensor falls under a certain threshold. This function node should now trigger two things

1. Open my roller shutter (if closed) AND
2. Switch of the lights (when on)

This is what I tried in order to "split" the two comments for the different actions:

```auto
if (global.get("DayMode")== true)
    {
        msg.payload = "put:/nodes/74/attributes/271?target_value=0";
        return [msg, null]
        msg.payload = {"on": false};
        return [null, msg];
    }else{
        return null
    }

```

Obviously this didn´t work but maybe someone has an idea how to put that right 🙂

---

<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:** [25 June 2021 21:02 UTC](https://discourse.nodered.org/t/quo-vadis-function-nodes-with-multible-outputs/47681/2 "2021-06-25T21:02:48Z")

</div>

When you use ‘return’ you leave the function. Take a look in the documentation about the function node and it use of asynchronous messages

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [25 June 2021 21:11 UTC](https://discourse.nodered.org/t/quo-vadis-function-nodes-with-multible-outputs/47681/3 "2021-06-25T21:11:18Z")

</div>

Or return both payloads in same array.

```auto
if (global.get("DayMode")== true) {
    return [{payload: "put:/nodes/74/attributes/271?target_value=0"}, {payload: {"on": false}}]`;
}else{
    return null;
}

```

If you need to return other message parts, then you will need to clone the msg and then return the two messages with the altered payloads.

---

<div class="post-metadata">

**Author:** ![RonMa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ronma/32/42531_2.png) [@RonMa](https://discourse.nodered.org/u/RonMa)\
**Post date:** [25 June 2021 21:18 UTC](https://discourse.nodered.org/t/quo-vadis-function-nodes-with-multible-outputs/47681/4 "2021-06-25T21:18:35Z")

</div>

Beautiful @E1cid - that was exactly what I was looking for 😃 Btw: Way more helpful than these constant "look into the documentation" answers 😉

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 June 2021 07:07 UTC](https://discourse.nodered.org/t/quo-vadis-function-nodes-with-multible-outputs/47681/5 "2021-06-26T07:07:03Z")

</div>

> [@RonMa](#):
>
> Way more helpful than these constant "look into the documentation" answers

But have you learnt as much as if you had spent a little while reading the docs, reading relevant parts of the w3schools site and working out how to do it yourself?

---

<div class="post-metadata">

**Author:** ![RonMa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ronma/32/42531_2.png) [@RonMa](https://discourse.nodered.org/u/RonMa)\
**Post date:** [26 June 2021 08:44 UTC](https://discourse.nodered.org/t/quo-vadis-function-nodes-with-multible-outputs/47681/6 "2021-06-26T08:44:29Z")

</div>

No @Colin, in fact I learned more. Nothing is more helpful than learning by solving actual problems rather than just reading through documentations that might or might not address the issue one is trying to solve. Therefore, I´m really grateful if people take their precious time to drop me some lines of code that I can then use to go on with self-teaching.

---

<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:** [26 June 2021 10:55 UTC](https://discourse.nodered.org/t/quo-vadis-function-nodes-with-multible-outputs/47681/7 "2021-06-26T10:55:01Z")

</div>

> [@RonMa](#):
>
> Nothing is more helpful than learning by solving actual problems

I agree with you 100% but in this case, I gave you the reason your code wasn’t doing what you wanted it to do. Then I pointed you to the documentation that would give you your solution so you could learn more by solving your actual problem.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 June 2021 11:29 UTC](https://discourse.nodered.org/t/quo-vadis-function-nodes-with-multible-outputs/47681/8 "2021-06-26T11:29:43Z")

</div>

You did point out that the return ended the function, so second return is unreachable, but asynchronous messages was not the most relevant answer. All the OP really needed was pushing to send [both responses](https://nodered.org/docs/user-guide/writing-functions#multiple-messages) in the same return, he could of read about asynchronous messages all day with out understanding that he could send both payloads in one go.

Some people could read documents all day long and still not understand, then when they get a simple example it clicks. Either way the OP learnt what their issue was and learnt how to resolve it, so this discussion is just moot

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [26 June 2021 11:52 UTC](https://discourse.nodered.org/t/quo-vadis-function-nodes-with-multible-outputs/47681/9 "2021-06-26T11:52:57Z")

</div>

> [@E1cid](#):
>
> All the OP really needed was pushing to send [both responses](https://nodered.org/docs/user-guide/writing-functions#multiple-messages) in the same return

Or use `node.send()`[which emits a message without exiting the function](https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously)

There are always many roads leading to Rome 😉

RTFM: Finding and reading the docs is in many cases not easy. But pointing to the relevant pieces of the doc may help to A) solve the current problem and B) learn where to find information (in the future).

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 June 2021 12:02 UTC](https://discourse.nodered.org/t/quo-vadis-function-nodes-with-multible-outputs/47681/10 "2021-06-26T12:02:13Z")

</div>

> [@Christian-Me](#):
>
> Or use `node.send()` [which emits a message without exiting the function](https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously)

Yes there are many ways to skin a cat, but As said not the most relevant. there was no need to use asynchronous messages. Again this is moot.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 July 2021 12:02 UTC](https://discourse.nodered.org/t/quo-vadis-function-nodes-with-multible-outputs/47681/11 "2021-07-10T12:02:38Z")

</div>

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