# Two messages in one function

**URL:** <https://discourse.nodered.org/t/two-messages-in-one-function/54893>\
**Category:** General\
**Created:** [8 December 2021 21:21 UTC](https://discourse.nodered.org/t/two-messages-in-one-function/54893 "2021-12-08T21:21:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dokho](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@dokho](https://discourse.nodered.org/u/dokho)\
**Post date:** [8 December 2021 21:21 UTC](https://discourse.nodered.org/t/two-messages-in-one-function/54893/1 "2021-12-08T21:21:02Z")

</div>

Hi !

First sorry for my bad english 🙂

I'm trying to make a node-red function to send two msg.

One of these message contain a variable.

The messages must be like this:

- msg1: NEXTION,conschauf.txt="19"
- msg2: NEXTION,p1.pic=8

The value "19" of msg1 is stored in node-red by an other node ( flow.set('consigneconfort', msg.payload.result[0].SetPoint); )

I have write this function:

```auto
msg.topic = "ECRAN-ENTREE/cmd";
if (flow.get('modeconfort') === "On") {
    var consigne = flow.get('consigneconfort');
    var msg1 = { payload: 'NEXTION,conschauf.txt="consigne"'};
    var msg2 = { payload: 'NEXTION,p1.pic=8' };
}
return [msg1, msg2];
```

but the result is:

- an "Invalid topic specified" error
- the first message is like this: "NEXTION,conschauf.txt="consigne""

Someone can help me to find the problem, please ?

Regards,

---

<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:** [8 December 2021 21:27 UTC](https://discourse.nodered.org/t/two-messages-in-one-function/54893/2 "2021-12-08T21:27:30Z")

</div>

> [@dokho](#):
>
> the first message is like this: "NEXTION,conschauf.txt="consigne""

To insert the value of `consigne` in the message payload, you can do the following.

```auto
var msg1 = { payload: `NEXTION,conschauf.txt="${consigne}"`};

```

As for the function - you are settings `msg.topic` but then return the `msg1` and `msg2` objects that don't have `topic` set. If you want the topic property to be set on those objects, you will need to set it:

```auto
var msg1 = { payload: `NEXTION,conschauf.txt="${consigne}"`, topic: "ECRAN-ENTREE/cmd"};
var msg2 = { payload: 'NEXTION,p1.pic=8', topic: "ECRAN-ENTREE/cmd" };

```

---

<div class="post-metadata">

**Author:** ![dokho](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@dokho](https://discourse.nodered.org/u/dokho)\
**Post date:** [8 December 2021 21:57 UTC](https://discourse.nodered.org/t/two-messages-in-one-function/54893/3 "2021-12-08T21:57:41Z")

</div>

Yes !!

Thank you very much 🙂

---

<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:** [22 December 2021 21:57 UTC](https://discourse.nodered.org/t/two-messages-in-one-function/54893/4 "2021-12-22T21:57:59Z")

</div>

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