# Changing the topic

**URL:** <https://discourse.nodered.org/t/changing-the-topic/9610>\
**Category:** General\
**Created:** [30 March 2019 12:04 UTC](https://discourse.nodered.org/t/changing-the-topic/9610 "2019-03-30T12:04:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![duncan-a](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/duncan-a/32/7182_2.png) [@duncan-a](https://discourse.nodered.org/u/duncan-a)\
**Post date:** [30 March 2019 12:04 UTC](https://discourse.nodered.org/t/changing-the-topic/9610/1 "2019-03-30T12:04:25Z")

</div>

I have an incoming MQTT message with msg.topic of "HA/Presence" and a msg.payload that varies depending on where it originated, so let's say it's "test".

I need to.create a msg.topic for the acknowledgement MQTT node of "HA/Presence\_response" plus the incoming msg.payload so, in this case, the outgoing msg.topic would be "HA/Presence\_response/test".

I've spent 9 hours Googling and playing with function and change nodes but I can't get it to work as required.

Any ideas???

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [30 March 2019 12:08 UTC](https://discourse.nodered.org/t/changing-the-topic/9610/2 "2019-03-30T12:08:58Z")

</div>

How to concatenate strings in javascript. [http://2ality.com/2011/10/string-concatenation.html](http://2ality.com/2011/10/string-concatenation.html)

msg.topic=msg.topic+”whatever/“+msg.payload

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [30 March 2019 14:45 UTC](https://discourse.nodered.org/t/changing-the-topic/9610/3 "2019-03-30T14:45:10Z")

</div>

Just jumping in and borrowing the thread 😉  
This is a very typical code segment I also use a lot. Until now, I tend to use a function node for such purposes. Typically, you wan't to add something to an incoming payload like

`msg.payload = "whatever"+msg.payload;`

I tried to figure out how to do it with a "standard" node like the Change node instead of using a lot of function nodes. I think you can use a JSONata expression in a Change node rule like

`'whatever' & payload`

So as an example for a solution to the topic authors question when using a Change node:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/83d1562e47a8f12147566b951f8db1e37c7c36b4.png)

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [30 March 2019 14:55 UTC](https://discourse.nodered.org/t/changing-the-topic/9610/4 "2019-03-30T14:55:42Z")

</div>

Another possible alternative is to use a standard Template node:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7887352aa6f52b4b1950d4120941b22075e8d252.png)
