# \`change\` node... not "working"? (And \`switch\` node)

**URL:** <https://discourse.nodered.org/t/change-node-not-working-and-switch-node/12478>\
**Category:** General\
**Created:** [22 June 2019 04:10 UTC](https://discourse.nodered.org/t/change-node-not-working-and-switch-node/12478 "2019-06-22T04:10:07Z")\
**Posts on this page:** 7\
**Page:** 1

<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:** [22 June 2019 04:10 UTC](https://discourse.nodered.org/t/change-node-not-working-and-switch-node/12478/1 "2019-06-22T04:10:07Z")

</div>

I am **trying** to use the `change` node.

I usually/normally use a `function` node and do it that way, but I am trying to get used to using the `change` node.

This packet is coming in:  
`{"topic":"STATUS/ADSL_Link_Status","payload":{"Who":"TelePi","Modem":"Online","Uplink":"Online"},"qos":2,"retain":false,"_msgid":"7cc00bf.510a0f4"}`  
And this is going out:  
`{"topic":"TelePi","payload":{"Who":"TelePi","Modem":"Online","Uplink":"Online"},"qos":2,"retain":false,"_msgid":"7cc00bf.510a0f4","Modem":"Online","Uplink":"Online"}`

And this is the node code:  
`[{"id":"4e10a2f6.ff28bc","type":"change","z":"15af81c5.64999e","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.Who","tot":"msg"},{"t":"set","p":"Modem","pt":"msg","to":"payload.Modem","tot":"msg"},{"t":"set","p":"Uplink","pt":"msg","to":"payload.Uplink","tot":"msg"},{"t":"set","p":"who","pt":"msg","to":"payload.who","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":4340,"wires":[["58a93b83.c6602c","21fb196.22199e6","983bb5dc.ae1ea8","6f170c9f.0a9d34"]]}]`

Now, I can see that the `msg.topic` has been set.  
And that `msg.payload.Modem` has become `msg.Modem`, and `msg.payload.Uplink` has become `msg.Uplink`

I am _saying_ that I created those two: `msg.Uplink` and `msg.Modem`.

So why hasn't `msg.who` being created too?

(And as if that was all my problems.)

I then try to process this message through more `switch` nodes.  
This is the flow part:

```auto
[{"id":"f4be63e.a8ced2","type":"json","z":"15af81c5.64999e","name":"","property":"payload","action":"","pretty":false,"x":540,"y":4340,"wires":[["fe3c0baf.e90bf8","4e10a2f6.ff28bc"]]},{"id":"4e10a2f6.ff28bc","type":"change","z":"15af81c5.64999e","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.Who","tot":"msg"},{"t":"set","p":"Modem","pt":"msg","to":"payload.Modem","tot":"msg"},{"t":"set","p":"Uplink","pt":"msg","to":"payload.Uplink","tot":"msg"},{"t":"set","p":"who","pt":"msg","to":"payload.who","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":4340,"wires":[["58a93b83.c6602c","21fb196.22199e6","983bb5dc.ae1ea8","6f170c9f.0a9d34"]]},{"id":"6f170c9f.0a9d34","type":"switch","z":"15af81c5.64999e","name":"Modem","property":"payload.Modem","propertyType":"msg","rules":[{"t":"cont","v":"Online","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":920,"y":4430,"wires":[["6a39103f.86a898"],["dddff52e.7420a"]]},{"id":"6a39103f.86a898","type":"debug","z":"15af81c5.64999e","name":"msg5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1050,"y":4420,"wires":[]},{"id":"dddff52e.7420a","type":"debug","z":"15af81c5.64999e","name":"msg6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1050,"y":4460,"wires":[]}]

```

I have tired editing the `switch` node to be either `msg.Modem` or `msg.payload.Modem`.

Neither seem to get through.

You will see that in that switch I test if the value is (or contains) "Online" and `otherwise` it goes to output 2.

Nothing comes out of either output of the `switch`.

I've been over it and over it and over it.

I don't get why the new "name" (`msg.who`) isn't being created when the other two are, and why the `switch` node isn't spitting the message out of output 2 - though I would have thought that as it says "Online" it would come out of #1.

---

<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:** [22 June 2019 04:24 UTC](https://discourse.nodered.org/t/change-node-not-working-and-switch-node/12478/2 "2019-06-22T04:24:57Z")

</div>

Here is a _test bed_ I made up to see if things work.

They seem to in this.

```auto
[{"id":"744982f7.41d894","type":"change","z":"15af81c5.64999e","name":"change","rules":[{"t":"set","p":"wibily","pt":"msg","to":"blah","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":4810,"wires":[["6d7a989d.73e2a","31e119e2.0b00e6"]]},{"id":"6d7a989d.73e2a","type":"switch","z":"15af81c5.64999e","name":"","property":"wibily","propertyType":"msg","rules":[{"t":"eq","v":"blah","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":600,"y":4790,"wires":[["6a05c34a.b7c96c"],["ed5b29d5.acda2"]]},{"id":"31e119e2.0b00e6","type":"debug","z":"15af81c5.64999e","name":"bad","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":590,"y":4750,"wires":[]},{"id":"6d689910.40efd8","type":"function","z":"15af81c5.64999e","name":"","func":"msg.wibily = \"blah\";\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":4770,"wires":[["6d7a989d.73e2a","31e119e2.0b00e6"]]},{"id":"6a05c34a.b7c96c","type":"debug","z":"15af81c5.64999e","name":"good","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":740,"y":4740,"wires":[]},{"id":"ed5b29d5.acda2","type":"debug","z":"15af81c5.64999e","name":"bad","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":740,"y":4830,"wires":[]},{"id":"b984cb8c.6fe24","type":"inject","z":"15af81c5.64999e","name":"","topic":"","payload":"message","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":4790,"wires":[["6d689910.40efd8"]]}]

```

Either way. With the `switch` or `function` node.  
Pressing the `inject` gets a **good** result.

---

<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:** [22 June 2019 04:54 UTC](https://discourse.nodered.org/t/change-node-not-working-and-switch-node/12478/3 "2019-06-22T04:54:39Z")

</div>

This is a definitive showing of the problem.  
Ok, you can't see the messages. But look at the nodes to which I am pointing in the pictures.

1:  
a:  
_RAW_ message. You can see it pass through that node.  
b:  
I set some parts of the message.  
c:  
You see the output on "msg7".  
Note: msg7 and msg5.

2:  
You can see the higher node configuration.  
Remember it didn't have any output in the previous picture.

3:  
This is the lower of the two `switch` nodes marked "MODEM".  
See how it is the same as the one in the previous picture.  
And that its "msg7" node has a result.

Why didn't "msg5" also have an output if the same message was sent to them both?

 ![Screenshot%20from%202019-06-22%2014-43-38](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/92fb602240b77543abed498a848b54cd145c3b18.png) ![Screenshot%20from%202019-06-22%2014-44-18](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6f54155fedd3dcb784dfd331897b36057321931c.png) ![Screenshot%20from%202019-06-22%2014-44-25](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/32c4f1b2291cfc246784e1e6f578bed72fd27292.png)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [22 June 2019 07:07 UTC](https://discourse.nodered.org/t/change-node-not-working-and-switch-node/12478/4 "2019-06-22T07:07:28Z")

</div>

> [@Trying\_to\_learn](#):
>
> So why hasn't `msg.who` being created too?

Because you are setting it to the value of `msg.payload.who` which doesn't exist. It should be `msg.payload.Who` if the sample message you shared is accurate.

---

<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:** [22 June 2019 07:10 UTC](https://discourse.nodered.org/t/change-node-not-working-and-switch-node/12478/5 "2019-06-22T07:10:00Z")

</div>

I am suspicious my SHIFT key has a hidden agenda to make my life miserable.

---

<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:** [22 June 2019 08:43 UTC](https://discourse.nodered.org/t/change-node-not-working-and-switch-node/12478/6 "2019-06-22T08:43:58Z")

</div>

Hi. Couple of suggestions that may help...

1. Be consistent in variable naming. E.g. choose a naming method like camelCase and stick to it. It will help at times like this. [See here](https://www.w3schools.com/js/js_conventions.asp)
2. Use the "copy path" button in the debug output that appears on the far right when you hover over a msg property. The exact and correct spelling will be copied to the clipboard ready to paste into your switch/change nodes. [See here](https://nodered.org/docs/user-guide/messages#understanding-the-structure-of-a-message)

---

<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:** [22 June 2019 08:57 UTC](https://discourse.nodered.org/t/change-node-not-working-and-switch-node/12478/7 "2019-06-22T08:57:05Z")

</div>

Thanks.

I think that old things that were beaten into me aren't helping.

When I "start typing a new sentence", I put a capitol letter. That can be problematic with variable names and when I type the description in the block description.

But yes, I am trying to do what you said with the names and I do try to copy/paste names.
