# Disregard "undefined" msg

**URL:** <https://discourse.nodered.org/t/disregard-undefined-msg/60918>\
**Category:** General\
**Created:** [7 April 2022 06:21 UTC](https://discourse.nodered.org/t/disregard-undefined-msg/60918 "2022-04-07T06:21:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [7 April 2022 06:21 UTC](https://discourse.nodered.org/t/disregard-undefined-msg/60918/1 "2022-04-07T06:21:18Z")

</div>

In a normal situation my payload is like this:  
1:13.5230:14.0900:0.0000:0.0000:24:24:216:216

Time to time I get back messages like this:

> Cells : msg : Object  
> object  
> payload: object  
> NaNVCNaN: undefined  
> NaNTCNaN: undefined  
> \_msgid: "01b9257b73bb0ea0"  
> topic: "Cells"

I did try to filter out such type of messages using:

```auto
if(isNaN(msg.payload)) {
  return null; //halt flow
}
return msg;

```

and

```auto
if(msg.payload=="") {
  return null; //halt flow
}
return msg;

```

but are still going trough.  
How do I disregard such undefined messages?

---

<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:** [7 April 2022 08:45 UTC](https://discourse.nodered.org/t/disregard-undefined-msg/60918/2 "2022-04-07T08:45:02Z")

</div>

> [@FeliceM](#):
>
> I did try to filter out such type of messages using:
> 
> ```auto
> if(isNaN(msg.payload)) {
> return null; //halt flow
> }
> return msg;
> 
> ```
> 
> and
> 
> ```auto
> if(msg.payload=="") {
> return null; //halt flow
> }
> return msg;
> 
> ```
> 
> but are still going trough

They wont work as `payload` is an object ...

> [@FeliceM](#):
>
> payload: object

... so will never be caught by these tests.

  

Assuming your payload is NORMALLY a string as per your example above, you could change your "filter out" tests to ...

```auto
if(typeof msg.payload !== "string" || msg.payload == null) {
  return null; // halt flow because payload is NOT a string or is empty
}

```

---

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [7 April 2022 09:26 UTC](https://discourse.nodered.org/t/disregard-undefined-msg/60918/3 "2022-04-07T09:26:15Z")

</div>

Thanks for you help.  
My normal msg.payload is like this:

![Schermata 2022-04-07 alle 11.13.10](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/6655d87b34908a2e51d277cca02bc07e51f93dc2.png)

Despite the filter function I tried and even the one you suggested, at time this is still going trough:

![Schermata 2022-04-07 alle 11.22.24](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/9/a989d72c8c82cba1de1d63f7450dce9a9cea6c44.png)

---

<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:** [7 April 2022 09:33 UTC](https://discourse.nodered.org/t/disregard-undefined-msg/60918/4 "2022-04-07T09:33:23Z")

</div>

Try

```auto
if (msg.payload == "" || msg.payload == null) {
  return null; // halt flow because payload is an empty string
}

```

---

<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:** [7 April 2022 09:38 UTC](https://discourse.nodered.org/t/disregard-undefined-msg/60918/5 "2022-04-07T09:38:54Z")

</div>

> [@FeliceM](#):
>
> My normal msg.payload is like this:

ok, so your normal payload is a string. So the suggestion I made should get you closer to a solution as it will discard empty strings and non strings...

> [@Steve-Mcl](#):
>
> ```auto
> if(typeof msg.payload !== "string" || msg.payload == null) {
> return null; // halt flow because payload is NOT a string or is empty
> }
> 
> ```

> [@FeliceM](#):
>
> Despite the filter function I tried and even the one you suggested, at time this is still going trough:
> 
> ![Schermata 2022-04-07 alle 11.22.24](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/9/a989d72c8c82cba1de1d63f7450dce9a9cea6c44.png)

Looking at this 👆screenshot, it seems payload has (potentially) a newline character in it. so you could trim it...

```auto
if(typeof msg.payload !== "string" || msg.payload.trim() == "") {
  return null; // halt flow because payload is NOT a string or is empty
}

```

---

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [7 April 2022 10:25 UTC](https://discourse.nodered.org/t/disregard-undefined-msg/60918/6 "2022-04-07T10:25:18Z")

</div>

> [@zenofmud](#):
>
> ```auto
> if (msg.payload == "" || msg.payload == null) {
> return null; // halt flow because payload is an empty string
> }
> 
> ```

Thank you but unfortunately this doesn't work in my case

---

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [7 April 2022 10:25 UTC](https://discourse.nodered.org/t/disregard-undefined-msg/60918/7 "2022-04-07T10:25:44Z")

</div>

Thank you. Problem solved.

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [7 April 2022 11:38 UTC](https://discourse.nodered.org/t/disregard-undefined-msg/60918/8 "2022-04-07T11:38:01Z")

</div>

You can also use a switch node and filter all message which are not null. No need to use a function node.

---

<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:** [21 April 2022 11:38 UTC](https://discourse.nodered.org/t/disregard-undefined-msg/60918/9 "2022-04-21T11:38:05Z")

</div>

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