# Msg.property are lost between nodes

**URL:** https://discourse.nodered.org/t/msg-property-are-lost-between-nodes/76935
**Category:** General
**Created:** [25 March 2023 15:34 UTC](https://discourse.nodered.org/t/msg-property-are-lost-between-nodes/76935 "2023-03-25T15:34:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hary/32/12340_2.png) [@hary](https://discourse.nodered.org/u/hary)
#### Post date: [25 March 2023 15:34 UTC](https://discourse.nodered.org/t/msg-property-are-lost-between-nodes/76935/1 "2023-03-25T15:34:26Z")

</div>

Great Nodered users.

I've the below flow where the msg is supposed to have multiple properties, but it seems the properties are lost in between nodes !

```auto
[
    {
        "id": "a9eb292a6233f9f1",
        "type": "inject",
        "z": "129b235eefae568b",
        "name": "",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            },
            {
                "p": "state",
                "v": "OFF",
                "vt": "str"
            },
            {
                "p": "background",
                "v": "RED",
                "vt": "str"
            },
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "inverter",
        "payload": "false",
        "payloadType": "bool",
        "x": 110,
        "y": 60,
        "wires": [
            [
                "2437fb407f0c0b44",
                "234ba221963d2297"
            ]
        ]
    },
    {
        "id": "9079ecab67bcd03b",
        "type": "change",
        "z": "129b235eefae568b",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "background",
                "pt": "msg",
                "from": "RED",
                "fromt": "str",
                "to": "GREEN",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "state",
                "pt": "msg",
                "from": "OFF",
                "fromt": "str",
                "to": "ON",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "background",
                "pt": "msg",
                "from": "GREEN",
                "fromt": "str",
                "to": "RED",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "state",
                "pt": "msg",
                "from": "ON",
                "fromt": "str",
                "to": "OFF",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "true",
                "fromt": "bool",
                "to": "false",
                "tot": "bool"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "false",
                "fromt": "bool",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 480,
        "y": 60,
        "wires": [
            [
                "d685e5a3ea2915fc",
                "2437fb407f0c0b44"
            ]
        ]
    },
    {
        "id": "d685e5a3ea2915fc",
        "type": "debug",
        "z": "129b235eefae568b",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 660,
        "y": 60,
        "wires": []
    },
    {
        "id": "2437fb407f0c0b44",
        "type": "ui_button",
        "z": "129b235eefae568b",
        "name": "",
        "group": "d488c32a39e6b090",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "{{msg.state}}",
        "tooltip": "",
        "color": "",
        "bgcolor": "{{msg.background}}",
        "className": "",
        "icon": "",
        "payload": "false",
        "payloadType": "bool",
        "topic": "inverter",
        "topicType": "msg",
        "x": 250,
        "y": 60,
        "wires": [
            [
                "9079ecab67bcd03b",
                "565d1c11f6297a74"
            ]
        ]
    },
    {
        "id": "565d1c11f6297a74",
        "type": "debug",
        "z": "129b235eefae568b",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 460,
        "y": 20,
        "wires": []
    },
    {
        "id": "234ba221963d2297",
        "type": "debug",
        "z": "129b235eefae568b",
        "name": "debug 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 260,
        "y": 20,
        "wires": []
    },
    {
        "id": "d488c32a39e6b090",
        "type": "ui_group",
        "name": "dashboard_group_1",
        "tab": "a7d5e487503829e6",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "a7d5e487503829e6",
        "type": "ui_tab",
        "name": "dashboard_tab_1",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

```

What do I do wrong ?  
The button is supposed to change background colour on each click as the msg.state is supposed to swap from true to false or false to true.

---

<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: [25 March 2023 16:07 UTC](https://discourse.nodered.org/t/msg-property-are-lost-between-nodes/76935/2 "2023-03-25T16:07:18Z")

</div>

Hi @hary.

I don't use dashboard - But I'm sure, by default, it doesn't send everything it was simply set with, i.e, it will only send a `payload` (and maybe `topic`) - therefore, your change node is not finding the properties it needs to change - and when sending it back through, you are only changing the `payload` and `topic`.

I could be wrong of course - and sure it can be configured to do so.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [25 March 2023 16:09 UTC](https://discourse.nodered.org/t/msg-property-are-lost-between-nodes/76935/3 "2023-03-25T16:09:48Z")

</div>

You are using the change node wrongly.  
First you change RED to GREEN, then you go on to change GREEN to RED.

 ![Untitled 2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/0613782513b1b7326ae6df2155ef9a84e18eb183.jpeg)

One way around this is to use a temporary third value:

 ![Untitled 3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/d/4d6620a640744551f6b2657763ca483eeee8ad6f.jpeg)

---

<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: [25 March 2023 16:10 UTC](https://discourse.nodered.org/t/msg-property-are-lost-between-nodes/76935/4 "2023-03-25T16:10:48Z")

</div>

Hi , this example may help the payload is stored in context, as the button will not pass the state and background. Also colour and state are set using payload.  
e.g.

```auto
[{"id":"a9eb292a6233f9f1","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"inverter","payload":"false","payloadType":"bool","x":130,"y":4100,"wires":[["9079ecab67bcd03b"]]},{"id":"9079ecab67bcd03b","type":"change","z":"65617ffeb779f51c","name":"","rules":[{"t":"set","p":"background","pt":"msg","to":"$$.payload = true ? \"red\" :\"green\"","tot":"jsonata"},{"t":"set","p":"state","pt":"msg","to":"$$.payload = true ? \"ON\": \"OFF\" ","tot":"jsonata"},{"t":"set","p":"switch_state","pt":"flow","to":"$$.payload = true ? false : true","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":4140,"wires":[["2437fb407f0c0b44"]]},{"id":"2437fb407f0c0b44","type":"ui_button","z":"65617ffeb779f51c","name":"","group":"d488c32a39e6b090","order":1,"width":0,"height":0,"passthru":false,"label":"{{msg.state}}","tooltip":"","color":"","bgcolor":"{{msg.background}}","className":"","icon":"","payload":"switch_state","payloadType":"flow","topic":"inverter","topicType":"msg","x":510,"y":4140,"wires":[["d685e5a3ea2915fc","9079ecab67bcd03b"]]},{"id":"d685e5a3ea2915fc","type":"debug","z":"65617ffeb779f51c","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":4100,"wires":[]},{"id":"d488c32a39e6b090","type":"ui_group","name":"dashboard_group_1","tab":"a7d5e487503829e6","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"a7d5e487503829e6","type":"ui_tab","name":"dashboard_tab_1","icon":"dashboard","disabled":false,"hidden":false}]

```

You can do similar without context, but it means adding the payload to the topic as that is the only msg var that can be set in the button node.  
e.g.

```auto
[{"id":"55bedbea4e6bb0fd","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"inverter1","payload":"false","payloadType":"bool","x":150,"y":4160,"wires":[["49cfd617ccad660e"]]},{"id":"49cfd617ccad660e","type":"change","z":"65617ffeb779f51c","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"[$$.topic, $$.payload = true ? false : true]","tot":"jsonata"},{"t":"set","p":"background","pt":"msg","to":"$$.topic[1] = true ? \"green\" :\"red\"","tot":"jsonata"},{"t":"set","p":"state","pt":"msg","to":"$$.topic[1] = true ? \"OFF\" : \"ON\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":4160,"wires":[["39ecebf2b74fe56b"]]},{"id":"6486c21cea76bea6","type":"change","z":"65617ffeb779f51c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"topic[1]","tot":"msg"},{"t":"move","p":"topic[0]","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":4160,"wires":[["49cfd617ccad660e","b0e246c0a40c9096"]]},{"id":"39ecebf2b74fe56b","type":"ui_button","z":"65617ffeb779f51c","name":"","group":"2d4fe667.28f8ba","order":1,"width":0,"height":0,"passthru":false,"label":"{{msg.state}}","tooltip":"","color":"","bgcolor":"{{msg.background}}","className":"","icon":"","payload":"inverter1","payloadType":"str","topic":"topic","topicType":"msg","x":530,"y":4160,"wires":[["6486c21cea76bea6"]]},{"id":"b0e246c0a40c9096","type":"debug","z":"65617ffeb779f51c","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":720,"y":4120,"wires":[]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":2,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

---

<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: [24 May 2023 16:11 UTC](https://discourse.nodered.org/t/msg-property-are-lost-between-nodes/76935/5 "2023-05-24T16:11:04Z")

</div>

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