# RETURN a Payload and a Topic with Function like a injectnode

**URL:** <https://discourse.nodered.org/t/return-a-payload-and-a-topic-with-function-like-a-injectnode/82478>\
**Category:** General\
**Created:** [30 October 2023 22:01 UTC](https://discourse.nodered.org/t/return-a-payload-and-a-topic-with-function-like-a-injectnode/82478 "2023-10-30T22:01:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![einfach112](https://avatars.discourse-cdn.com/v4/letter/e/3da27b/32.png) [@einfach112](https://discourse.nodered.org/u/einfach112)\
**Post date:** [30 October 2023 22:01 UTC](https://discourse.nodered.org/t/return-a-payload-and-a-topic-with-function-like-a-injectnode/82478/1 "2023-10-30T22:01:24Z")

</div>

Hello everyone, With an inject node as shown in the photo I manage to send a payload with the content 139790555651 and at the same time a topic with the content 120 (the values don't matter)  
Here is a picture of the functioning Injectnode and the contents of the debug  
 ![injectnode](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/d/2d489f84e7646a0df4940f85bc95b1b4a8558698.png)  
 ![injectnoderesult](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/5/a570de4ee84b85cff7cc6851ba3d686a7cdf1fd7.png)

If I use the inject node then my function behind it works perfectly.  
Now I would like to replace the injectnode with a function.  
However, only the payload arrives at the end. I don't get the topic name.  
Here is my function node and the contents of the debug  
As you can see, the topic is not transferred!?

 ![functionnode](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/a/ea3a04b8ebafe9163840a0bdac829bbc73fce448.png)  
 ![functionnoderesult](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fdd954f28d102c7a1541bf4f4a0021c3e2fded8c.png)

So it seems to be an error in my function. Can someone tell me how to change my function so that both the contents of Payload and Topic are sent?  
Thank you in advance as always

here is the code to change:

```auto
var DerStatus = msg.payload;
if (DerStatus === "Geöffnet") {
    return [
        { payload: 300 },
        { topic: '139790555651'}
    ]
}
else {
    return [
        { payload: 0 },
        { topic: '139790555651'}
    ]
}

```

---

<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:** [30 October 2023 22:05 UTC](https://discourse.nodered.org/t/return-a-payload-and-a-topic-with-function-like-a-injectnode/82478/2 "2023-10-30T22:05:31Z")

</div>

Hi @einfach112

> [@einfach112](#):
>
> ```auto
> return [
> { payload: 300 },
> { topic: '139790555651'}
> ]
> 
> ```

That is sending an array of messages.

To send 1 message with both properties.

```auto
return { payload: 300, topic: '139790555651'}

```

---

<div class="post-metadata">

**Author:** ![einfach112](https://avatars.discourse-cdn.com/v4/letter/e/3da27b/32.png) [@einfach112](https://discourse.nodered.org/u/einfach112)\
**Post date:** [31 October 2023 06:59 UTC](https://discourse.nodered.org/t/return-a-payload-and-a-topic-with-function-like-a-injectnode/82478/3 "2023-10-31T06:59:54Z")

</div>

THANK YOU for your Backup ! IT WORKS!

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [31 October 2023 23:38 UTC](https://discourse.nodered.org/t/return-a-payload-and-a-topic-with-function-like-a-injectnode/82478/4 "2023-10-31T23:38:27Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/5/65607a87c663e81f787a9b973ae912804e9888a1.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/6/36c682fa5762bcf162a27c1a4f48042802c719a5.png)

---

<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:** [14 November 2023 23:39 UTC](https://discourse.nodered.org/t/return-a-payload-and-a-topic-with-function-like-a-injectnode/82478/5 "2023-11-14T23:39:03Z")

</div>

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