# Can I return a real null value to a multi out function from an else if statement?

**URL:** <https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852>\
**Category:** General\
**Created:** [23 January 2024 23:21 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852 "2024-01-23T23:21:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikefila](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikefila/32/95223_2.png) [@mikefila](https://discourse.nodered.org/u/mikefila)\
**Post date:** [23 January 2024 23:21 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/1 "2024-01-23T23:21:58Z")

</div>

~~The way it is now, if it returns null, it will fire a null message. I'd like it to not fire at all.~~

This works as is, problem was from bad formatting further up in my code. `msg2 = null`

```auto
let msg2 = {};
if (phoneState === "offhook") {
    msg2 = null;
} else if (ivsRule === "ivs"){
    msg2.payload = ((cameraName.toLowerCase()).replace(/xvr /, "")).replace(/ floor/, "");
} else {
    msg2.payload = ivsRule;
};

return [msg1, msg2];

```

Another problem I am having is trying to use an or statement like so but it seems to let everything pass.

```auto
(evco === "CrossRegionDetection" && action === "Start" && ivsRule === "first" || "second" || "third")

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [24 January 2024 00:11 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/2 "2024-01-24T00:11:02Z")

</div>

> [@mikefila](#):
>
> if it returns null,

If what returns null?

> [@mikefila](#):
>
> I'd like it to not fire at all

Which output both output 1 and output 2?

To not send anything, `return null`

---

<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:** [24 January 2024 00:21 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/3 "2024-01-24T00:21:19Z")

</div>

> [@mikefila](#):
>
> The way it is now, if it returns null, it will fire a null message. I'd like it to not fire at all.

I'm not sure I get what you mean by that.

If `phoneState === "offhook"` you get no output on the second output of the node.

What do you mean by a **real null** in the title?

`null` means nothing is sent.

You may be confused with the terms. (Not sure).  
Just asking.

---

<div class="post-metadata">

**Author:** ![mikefila](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikefila/32/95223_2.png) [@mikefila](https://discourse.nodered.org/u/mikefila)\
**Post date:** [24 January 2024 00:24 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/4 "2024-01-24T00:24:17Z")

</div>

An empty object with just a message id

![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/b/5b6c9989ca8a67bebdcbcb5fa5ffea335850d052.jpeg)

---

<div class="post-metadata">

**Author:** ![mikefila](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikefila/32/95223_2.png) [@mikefila](https://discourse.nodered.org/u/mikefila)\
**Post date:** [24 January 2024 00:25 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/5 "2024-01-24T00:25:14Z")

</div>

if I use `[msg1, null]` there is no output. Hard coded.

---

<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:** [24 January 2024 00:27 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/6 "2024-01-24T00:27:54Z")

</div>

Ok, so in your code:

Line 3.

`msg2 = null;`

Try `msg2.payload = "";`

See if that does what you want.

Sorry, I am only guessing at what you want.  
Please don't get upset. I know sometimes it is hard to explain things in the exact words others understand.  
Not sure if it is `msg2.payload` or just `msg2`.

---

<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:** [24 January 2024 00:31 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/7 "2024-01-24T00:31:09Z")

</div>

If you are looking (on output 2) for a _certain message_ to identify the phone is offhook, you could do it a different way:

```auto
let msg2 = {};
if (phoneState === "offhook") {
    msg2.payload = "offhook";
} else if (ivsRule === "ivs"){
    msg2.payload = ((cameraName.toLowerCase()).replace(/xvr /, "")).replace(/ floor/, "");
} else {
    msg2.payload = ivsRule;
};

return [msg1, msg2];

```

then in the next node connected to output 2, look for the message `offhook` and act on that.

Again, just offering ideas.

---

<div class="post-metadata">

**Author:** ![mikefila](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikefila/32/95223_2.png) [@mikefila](https://discourse.nodered.org/u/mikefila)\
**Post date:** [24 January 2024 00:34 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/8 "2024-01-24T00:34:34Z")

</div>

No worries, I've been on forums for a long time. Sending `""` Worked as expected with no message. That is a tts output to my phone. I don't want it to go off if I'm on the phone.

I appreciate your help.

---

<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:** [24 January 2024 00:35 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/9 "2024-01-24T00:35:32Z")

</div>

Hey, no worries.

Sorry I couldn't help you more, but maybe I have helped you understand it a bit more.  
And that would be a good thing.

All the best.

---

<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:** [24 January 2024 00:37 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/10 "2024-01-24T00:37:02Z")

</div>

If that one with the `msg2.payload = ""` worked, mark it as the solution.

That helps others with this problem see the answer.

---

<div class="post-metadata">

**Author:** ![mikefila](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikefila/32/95223_2.png) [@mikefila](https://discourse.nodered.org/u/mikefila)\
**Post date:** [24 January 2024 00:37 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/11 "2024-01-24T00:37:32Z")

</div>

Does clicking solution close the thread on this forum? I just want to leave it open to possibly get an answer to my other question without making a new post.

---

<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:** [24 January 2024 00:38 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/12 "2024-01-24T00:38:46Z")

</div>

Oh. Yes it would _solve_ it.

But if there is still a question, by all means leave it open.

But it may help if you explain it a bit more, as I thought the question was answered.

It may be better if you post a new thread, as a thread with 2 questions in it is a bit confusing.  
(Just saying.)

---

<div class="post-metadata">

**Author:** ![mikefila](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikefila/32/95223_2.png) [@mikefila](https://discourse.nodered.org/u/mikefila)\
**Post date:** [24 January 2024 00:40 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/13 "2024-01-24T00:40:39Z")

</div>

> [@mikefila](#):
>
> Another problem I am having is trying to use an or statement like so but it seems to let everything pass.
> 
> `(evco === "CrossRegionDetection" && action === "Start" && ivsRule === "first" || "second" || "third" )`

This question.

---

<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:** [24 January 2024 00:42 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/14 "2024-01-24T00:42:06Z")

</div>

Well, while _we_ are here... 😉

`(evco === "CrossRegionDetection" && action === "Start" && ivsRule === "first" || "second" || "third")`

How about you explain to me - as I am not understanding it - what you want to do?

To me the structure looks ..... _wrong_ somehow.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [24 January 2024 00:43 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/15 "2024-01-24T00:43:48Z")

</div>

> [@mikefila](#):
>
> (evco === "CrossRegionDetection" && action === "Start" && ivsRule === "first" || "second" || "third" )

Should be

```auto
if (evco === "CrossRegionDetection" && action === "Start" && (ivsRule === "first" || ivsRule === "second" || ivsRule ==="third") )

```

---

<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:** [24 January 2024 00:44 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/16 "2024-01-24T00:44:33Z")

</div>

Thanks @Steve-Mcl

Yeah, the `( )` around it were throwing me.

I could see _something_ but couldn't quite put my finger on it.

---

<div class="post-metadata">

**Author:** ![mikefila](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikefila/32/95223_2.png) [@mikefila](https://discourse.nodered.org/u/mikefila)\
**Post date:** [24 January 2024 00:47 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/17 "2024-01-24T00:47:56Z")

</div>

It is, it's just a snippet. That snippet returns true even if some of the string variables don't match. When I break them up they work.

```auto
let msg1 = {};
if (evco === "CrossRegionDetection" && action === "Start" && ivsRule === "ivs") {msg1.payload = {
    domain: "camera",
    service: "snapshot",
    data: {
        "entity_id": cameraEntity,
    },
    topic: 'single',
    title: cameraName,
};
} else if (evco === "CrossRegionDetection" && action === "Start" && ivsRule === "first" ) {msg1.payload = {
    domain: "camera",
    service: "snapshot",
    data: {
        "entity_id": cameraEntity,
    },
    topic: 'multi',
    title: ivsRule,
};
} else if (evco === "CrossRegionDetection" && action === "Start" && ivsRule === "basement") {msg1.payload = {
    domain: "camera",
    service: "snapshot",
    data: {
        "entity_id": cameraEntity,
    },
    topic: 'multi',
    title: ivsRule,
};
} else if (evco === "CrossRegionDetection" && action === "Start" && ivsRule === "alley") {msg1.payload = {
    domain: "camera",
    service: "snapshot",
    data: {
        "entity_id": cameraEntity,
    },
    topic: 'multi',
    title: ivsRule,
};
} else if (evco === "CrossRegionDetection" && action === "Start" && ivsRule === "garden") {msg1.payload = {
    domain: "camera",
    service: "snapshot",
    data: {
        "entity_id": cameraEntity,
    },
    topic: 'multi',
    title: ivsRule,
};
} else if (evco === "VideoMotion" && action === "Start") {msg1.payload = {
    domain: "camera",
    service: "snapshot",
    data: {
        "entity_id": cameraEntity,
    },
    topic: 'motion',
    title: cameraName,
};
} else {
    ""
};

```

---

<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:** [24 January 2024 00:49 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/18 "2024-01-24T00:49:38Z")

</div>

Sorry, but that post helps a lot in the context of what you are trying to do.

The first bit did leave some critical details out.

That is probably above my head.  
I'll look at it, but no promises on this part.

---

<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:** [24 January 2024 00:56 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/19 "2024-01-24T00:56:23Z")

</div>

Ok, maybe petty, but.....

```auto
msg1.payload = {domain: "camera", service: "snapshot", data: {"entity_id": cameraEntity},
    topic: 'single',
    title: cameraName,};
}

```

All parts should be in `"`.

So it should be:

```auto
msg1.payload = {"domain": "camera"," service": "snapshot", "data": {"entity_id": cameraEntity},
    "topic": 'single',
    "title": cameraName,};
}

```

That won't fix the problem, but if I remember correctly that is how it should be.

And:  
Not sure on how it would change things:  
At the end of each test: `return msg1;`

That may help, but I'm not sure.

And!

Just noticedL  
`data: {"entity_id": cameraEntity,}` is wrong.

Extra `,` in there after Entity  
Yes?

And an extra `,` at the end of most of the lines too.....

Or it seems to me to be extraneous.

---

<div class="post-metadata">

**Author:** ![mikefila](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikefila/32/95223_2.png) [@mikefila](https://discourse.nodered.org/u/mikefila)\
**Post date:** [24 January 2024 01:13 UTC](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852/20 "2024-01-24T01:13:02Z")

</div>

Yeah I just saw a lot of errors and mix ups between `msg1` and `msg1.payload`. I don't know how anything was even going through. Let me clean everything up. The comma was extra.

[Next page](https://discourse.nodered.org/t/can-i-return-a-real-null-value-to-a-multi-out-function-from-an-else-if-statement/84852.md?page=2)
