# Why is switch not detecting msg.number is not empty

**URL:** <https://discourse.nodered.org/t/why-is-switch-not-detecting-msg-number-is-not-empty/81837>\
**Category:** General\
**Created:** [6 October 2023 15:48 UTC](https://discourse.nodered.org/t/why-is-switch-not-detecting-msg-number-is-not-empty/81837 "2023-10-06T15:48:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 October 2023 15:48 UTC](https://discourse.nodered.org/t/why-is-switch-not-detecting-msg-number-is-not-empty/81837/1 "2023-10-06T15:48:42Z")

</div>

Trying to detect presence of msg.number but this little test flow isn't working the way I think it should

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/c/7c5736961f710b33b87a70a4a77643764f0a4938.png)

can someone point out my error please?

```auto
[
    {
        "id": "c13f5e288b728ce1",
        "type": "debug",
        "z": "721af101b88d7036",
        "name": "debug 91",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 110,
        "wires": []
    },
    {
        "id": "2c83eb1b4f9b6232",
        "type": "switch",
        "z": "721af101b88d7036",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "cont",
                "v": "hive boost ",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 320,
        "y": 110,
        "wires": [
            [
                "108cbb6ccd74a2ed",
                "cf738b0d0f6105aa"
            ]
        ]
    },
    {
        "id": "108cbb6ccd74a2ed",
        "type": "switch",
        "z": "721af101b88d7036",
        "name": "",
        "property": "number",
        "propertyType": "msg",
        "rules": [
            {
                "t": "nempty"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 490,
        "y": 110,
        "wires": [
            [
                "c13f5e288b728ce1"
            ]
        ]
    },
    {
        "id": "cf738b0d0f6105aa",
        "type": "debug",
        "z": "721af101b88d7036",
        "name": "debug 92",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 500,
        "y": 160,
        "wires": []
    },
    {
        "id": "dda9c034355ef2c4",
        "type": "inject",
        "z": "721af101b88d7036",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "number",
                "v": "19",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "hive boost one nine minutes",
        "payloadType": "str",
        "x": 140,
        "y": 110,
        "wires": [
            [
                "2c83eb1b4f9b6232"
            ]
        ]
    },
    {
        "id": "7310cd17f2232891",
        "type": "inject",
        "z": "721af101b88d7036",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "hive boost on",
        "payloadType": "str",
        "x": 160,
        "y": 160,
        "wires": [
            [
                "2c83eb1b4f9b6232"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [6 October 2023 16:00 UTC](https://discourse.nodered.org/t/why-is-switch-not-detecting-msg-number-is-not-empty/81837/2 "2023-10-06T16:00:23Z")

</div>

From the node help:

The `is empty` and `is not empty` rules can be used to test the length of Strings, Arrays and Buffers, or the number of properties an Object has. Neither rule will pass if the property being tested has a `boolean` , `null` or `undefined` value.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [6 October 2023 16:06 UTC](https://discourse.nodered.org/t/why-is-switch-not-detecting-msg-number-is-not-empty/81837/3 "2023-10-06T16:06:33Z")

</div>

Or are you wanting to detect that the property itself is present?

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 October 2023 16:12 UTC](https://discourse.nodered.org/t/why-is-switch-not-detecting-msg-number-is-not-empty/81837/4 "2023-10-06T16:12:55Z")

</div>

Aah - that would explain why it doesn't work ☹

I only want the message to pass if it contains the msg.number property

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [6 October 2023 16:13 UTC](https://discourse.nodered.org/t/why-is-switch-not-detecting-msg-number-is-not-empty/81837/5 "2023-10-06T16:13:03Z")

</div>

This might be better?

![Screenshot 2023-10-06 at 17.12.46](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/069063b10e67415649942d8db94e680c5c08c9da.png)

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 October 2023 16:14 UTC](https://discourse.nodered.org/t/why-is-switch-not-detecting-msg-number-is-not-empty/81837/6 "2023-10-06T16:14:07Z")

</div>

Yep - that does the job 🙂

---

<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:** [20 October 2023 16:14 UTC](https://discourse.nodered.org/t/why-is-switch-not-detecting-msg-number-is-not-empty/81837/7 "2023-10-20T16:14:57Z")

</div>

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