# Trying to build message with CHANGE node. Not working

**URL:** <https://discourse.nodered.org/t/trying-to-build-message-with-change-node-not-working/23393>\
**Category:** General\
**Created:** [21 March 2020 05:25 UTC](https://discourse.nodered.org/t/trying-to-build-message-with-change-node-not-working/23393 "2020-03-21T05:25:20Z")\
**Posts on this page:** 6\
**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:** [21 March 2020 05:25 UTC](https://discourse.nodered.org/t/trying-to-build-message-with-change-node-not-working/23393/1 "2020-03-21T05:25:20Z")

</div>

(And `template` node.)

This is the flow: (Basic)

```auto
[{"id":"15ae0152.83044f","type":"inject","z":"675e227d.d158b4","name":"Weekly","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"50 23 * * 0","once":false,"onceDelay":0.1,"x":160,"y":1990,"wires":[["c99fea29.aeaf1"]]},{"id":"c99fea29.aeaf1","type":"moment","z":"675e227d.d158b4","name":"","topic":"","input":"","inputType":"msg","inTz":"Australia/Sydney","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-ww","locale":"en_AU","output":"","outputType":"msg","outTz":"Australia/Sydney","x":390,"y":1990,"wires":[["8ed6e064.5d98e","d8d204f7.310a8"]]},{"id":"8ed6e064.5d98e","type":"change","z":"675e227d.d158b4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"directory","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"log_paths","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":1990,"wires":[["791399b9.493ee","8921a9ee.bfb6d8"]]},{"id":"791399b9.493ee","type":"template","z":"675e227d.d158b4","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}}reboot","output":"str","x":790,"y":1990,"wires":[["74e6ce8a.becc68"]]},{"id":"d8d204f7.310a8","type":"function","z":"675e227d.d158b4","name":"","func":"msg.directory = msg.payload;\n\nvar path = global.get(\"log_paths\");\nmsg.path = path + \"reboot/\";\n\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":2030,"wires":[["d5e9569e.50cea"]]},{"id":"d5e9569e.50cea","type":"debug","z":"675e227d.d158b4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":710,"y":2100,"wires":[]},{"id":"74e6ce8a.becc68","type":"debug","z":"675e227d.d158b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":980,"y":1920,"wires":[]}]

```

Generate `timestamp`, feed it into `moment` node to get format `YYYY-ww`, send that to a `change` node to set the _msg.directory_ to that path - sort of, into `template` node to append to the path name, which is held in _msg.payload_.

Ok, the `global` stuff:  
given `log_paths` is set to: `/media/pi/06BB-C87D/logs/`

So at this stage I would expect:  
`msg.directory` to be `2020-12`  
and  
`msg.payload` to be `/media/pi/06BB-C87D/logs/reboot`

This is what I get/see:

```auto
{"_msgid":"b3cea20a.1254b","topic":"","directory":"2020-12","payload":"&#x2F;media&#x2F;pi&#x2F;06BB-C87D&#x2F;logs&#x2F;reboot"}

```

But if I go down the lower path via the `function` node I get:

```auto
{"_msgid":"b3cea20a.1254b","topic":"","payload":"2020-12","directory":"2020-12","path":"/media/pi/06BB-C87D/logs/reboot/"}

```

Which looks a lot better than the first one.

Ok, the second one does it a bit differently. I gives me `msg.path` and `msg.directory`  
Hope you can get what I am wanting to do.

Where's the _elephant_?

---

<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:** [21 March 2020 08:24 UTC](https://discourse.nodered.org/t/trying-to-build-message-with-change-node-not-working/23393/2 "2020-03-21T08:24:15Z")

</div>

Try using `{{{payload}}}reboot` in the template node

---

<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:** [21 March 2020 08:25 UTC](https://discourse.nodered.org/t/trying-to-build-message-with-change-node-not-working/23393/3 "2020-03-21T08:25:55Z")

</div>

(I gotta ask)

Why the 3 `{` ?

In the example in the `template` node there are only 2.

But thanks for the reply.

---

<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:** [21 March 2020 08:31 UTC](https://discourse.nodered.org/t/trying-to-build-message-with-change-node-not-working/23393/4 "2020-03-21T08:31:55Z")

</div>

Google search 'mustache syntax'

from [Mustache Reference](https://scalate.github.io/scalate/documentation/mustache.html)

> All values are HTML escaped by default. If you want to return unescaped HTML use the triple mustache **{{{name}}}**. Or you can use **{{& name}}**

---

<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:** [21 March 2020 08:37 UTC](https://discourse.nodered.org/t/trying-to-build-message-with-change-node-not-working/23393/5 "2020-03-21T08:37:41Z")

</div>

It was knowing it is "mustache syntax"..... Yeah, I have heard of it, but just hadn't put the two together.

---

<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:** [4 April 2020 08:37 UTC](https://discourse.nodered.org/t/trying-to-build-message-with-change-node-not-working/23393/6 "2020-04-04T08:37:44Z")

</div>

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