# How to set a specific topic to the output of a function node

**URL:** <https://discourse.nodered.org/t/how-to-set-a-specific-topic-to-the-output-of-a-function-node/75129>\
**Category:** General\
**Created:** [13 February 2023 20:10 UTC](https://discourse.nodered.org/t/how-to-set-a-specific-topic-to-the-output-of-a-function-node/75129 "2023-02-13T20:10:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flixm](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/flixm/32/17122_2.png) [@Flixm](https://discourse.nodered.org/u/Flixm)\
**Post date:** [13 February 2023 20:10 UTC](https://discourse.nodered.org/t/how-to-set-a-specific-topic-to-the-output-of-a-function-node/75129/1 "2023-02-13T20:10:34Z")

</div>

Hi,  
how can i set the function node to get a specific topic for the calculated output ? e.g.: "Wert"

or much better to get only the result of the calclation, and only if both topics are loaded?

```auto
if (msg.topic === "bezug") context.set("W1",msg.payload);
if (msg.topic === "pvplus") context.set("W2",msg.payload);

var W1 = context.get("W1") || 0;
var W2 = context.get("W2") || 0;

msg.payload = W2 - W1;
return msg;

```

---

<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:** [13 February 2023 20:42 UTC](https://discourse.nodered.org/t/how-to-set-a-specific-topic-to-the-output-of-a-function-node/75129/2 "2023-02-13T20:42:07Z")

</div>

![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b694aefa026ada55d0e200ef5fb92b8f6bde6fb2.jpeg)

```auto
[{"id":"f666d9b2662603c9","type":"inject","z":"6b7503f72b16f50f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"bezug","payload":"42","payloadType":"num","x":120,"y":100,"wires":[["823a77b9cbe585d3"]]},{"id":"690bf51451ad3433","type":"inject","z":"6b7503f72b16f50f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"pvplus","payload":"101","payloadType":"num","x":120,"y":180,"wires":[["823a77b9cbe585d3"]]},{"id":"823a77b9cbe585d3","type":"join","z":"6b7503f72b16f50f","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":270,"y":140,"wires":[["1f9983cdfb96e1a1"]]},{"id":"259678b0f2244ed8","type":"change","z":"6b7503f72b16f50f","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Wert","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":140,"wires":[["77c8ae21ad74b861"]]},{"id":"1f9983cdfb96e1a1","type":"change","z":"6b7503f72b16f50f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.bezug - payload.pvplus","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":140,"wires":[["259678b0f2244ed8"]]},{"id":"77c8ae21ad74b861","type":"debug","z":"6b7503f72b16f50f","name":"debug 258","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":810,"y":140,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Flixm](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/flixm/32/17122_2.png) [@Flixm](https://discourse.nodered.org/u/Flixm)\
**Post date:** [14 February 2023 16:02 UTC](https://discourse.nodered.org/t/how-to-set-a-specific-topic-to-the-output-of-a-function-node/75129/3 "2023-02-14T16:02:10Z")

</div>

hey,  
the first time i tried to work with a function node ... and it´s still easier to solve with standard nodes 🤪

---

<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:** [14 February 2023 16:11 UTC](https://discourse.nodered.org/t/how-to-set-a-specific-topic-to-the-output-of-a-function-node/75129/4 "2023-02-14T16:11:38Z")

</div>

Yup, it;s often a mistake to just reach for a function node.  
And you can combine the two change nodes into one for an even sleeker look.

---

<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:** [28 February 2023 16:12 UTC](https://discourse.nodered.org/t/how-to-set-a-specific-topic-to-the-output-of-a-function-node/75129/5 "2023-02-28T16:12:31Z")

</div>

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