# Mutiple outputs if statement

**URL:** <https://discourse.nodered.org/t/mutiple-outputs-if-statement/62515>\
**Category:** General\
**Tags:** function-node\
**Created:** [11 May 2022 15:06 UTC](https://discourse.nodered.org/t/mutiple-outputs-if-statement/62515 "2022-05-11T15:06:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Subsony](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Subsony](https://discourse.nodered.org/u/Subsony)\
**Post date:** [11 May 2022 15:06 UTC](https://discourse.nodered.org/t/mutiple-outputs-if-statement/62515/1 "2022-05-11T15:06:58Z")

</div>

Hey guys!

Im on my first jurney on Java an Node Red and have experienced actually some nice stuff. But actually im stuck and the documentation dont answer my quenstions or i dont understand it.

I want to split one if statement cases to two diffrent outputs. The first to payloads (tts & id) should be pushed to output 1 and the last two ( pushTopic & pushMessage) should be pushed to the second output, because the Alexa TTS and PushNot are causing troubles if i dont split them up.

Following my actual function node.

I hope i explained well.

```auto
if(msg.payload.presence == "home")
    {
        msg.payload.tts = 'Willkommen zu Hause! Schön dich zu sehen.'
        msg.payload.id = 'serialnumber'
        msg.payload.pushTopic = 'SYSTEM'
        msg.payload.pushMessage = 'Willkommen zu Hause!'
    }
return msg;

```

---

<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:** [11 May 2022 15:19 UTC](https://discourse.nodered.org/t/mutiple-outputs-if-statement/62515/2 "2022-05-11T15:19:02Z")

</div>

you need to create an array to send each msg to separate outputs,  
something like this

```auto
let output =[{payload:{}},{payload:{}}];
if(msg.payload.presence == "home"){
    output[0].payload.tts = 'Willkommen zu Hause! Schön dich zu sehen.'
    output[0].payload.id = 'serialnumber'
    output[1].payload.pushTopic = 'SYSTEM'
    output[1].payload.pushMessage = 'Willkommen zu Hause!'
}else{
    output = null
}
return output;

```

---

<div class="post-metadata">

**Author:** ![Subsony](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Subsony](https://discourse.nodered.org/u/Subsony)\
**Post date:** [11 May 2022 15:25 UTC](https://discourse.nodered.org/t/mutiple-outputs-if-statement/62515/3 "2022-05-11T15:25:20Z")

</div>

Thanks, mate. That helped me alot.

---

<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 2022 15:26 UTC](https://discourse.nodered.org/t/mutiple-outputs-if-statement/62515/4 "2022-07-10T15:26:09Z")

</div>

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