# Why is this reporting Undefined?

**URL:** <https://discourse.nodered.org/t/why-is-this-reporting-undefined/57182>\
**Category:** General\
**Tags:** debugging\
**Created:** [25 January 2022 03:03 UTC](https://discourse.nodered.org/t/why-is-this-reporting-undefined/57182 "2022-01-25T03:03:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheadehAnank](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@TheadehAnank](https://discourse.nodered.org/u/TheadehAnank)\
**Post date:** [25 January 2022 03:03 UTC](https://discourse.nodered.org/t/why-is-this-reporting-undefined/57182/1 "2022-01-25T03:03:22Z")

</div>

```auto
[
    {
        "id": "cdd592f25ffd2417",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "3a363a0b81b1330f",
        "type": "function",
        "z": "cdd592f25ffd2417",
        "name": "All Off, except scheduled",
        "func": "//On True, turn off all other zones\n\nlet minZN=1; let maxZN=65;\nlet onZN=[1,3,5];\n\nlet i = minZN;\n\nnode.status({fill:\"red\", shape:\"ring\", text:\" \"});\n\nznLoop(msg.payload)\n \nnode.status({fill:\"blue\", shape:\"ring\", text:' '});\n\nfunction znLoop(state) {\n \n setTimeout(function(){\n \n if (state && onZN.indexOf(i) == -1) {\n msg.payload.zone = i\n msg.payload.state = 0\n\n } else {\n msg.payload.zone = i\n msg.payload.state = 1\n\n }\n \n node.send(msg) \n \n i++\n if (i < maxZN) {\n znLoop(); }\n \n },1000)\n\n}\n\nreturn;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 530,
        "y": 320,
        "wires": [
            [
                "766a58d3e5670768"
            ]
        ]
    },
    {
        "id": "42641aeb99af6849",
        "type": "inject",
        "z": "cdd592f25ffd2417",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 320,
        "y": 320,
        "wires": [
            [
                "3a363a0b81b1330f"
            ]
        ]
    },
    {
        "id": "766a58d3e5670768",
        "type": "debug",
        "z": "cdd592f25ffd2417",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload.zone",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 800,
        "y": 320,
        "wires": []
    },
    {
        "id": "3444e4d2f15151cf",
        "type": "inject",
        "z": "cdd592f25ffd2417",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "false",
        "payloadType": "bool",
        "x": 320,
        "y": 380,
        "wires": [
            [
                "3a363a0b81b1330f"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [25 January 2022 03:53 UTC](https://discourse.nodered.org/t/why-is-this-reporting-undefined/57182/2 "2022-01-25T03:53:36Z")

</div>

Hi .. you cannot add properties to `msg.payload` if initially it was a different type.  
(in this case boolean)

define it as an object .. and tag on as many properties you like 😉

```auto
 setTimeout(function () {

        msg.payload = {} // empty object

        if (state && onZN.indexOf(i) == -1) {
            msg.payload.zone = i
            msg.payload.state = 0
   

        } else {
            msg.payload.zone = i
            msg.payload.state = 1
      
        }

```

---

<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:** [8 February 2022 03:54 UTC](https://discourse.nodered.org/t/why-is-this-reporting-undefined/57182/3 "2022-02-08T03:54:14Z")

</div>

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