# Writing functions to send more than 1 payload and topic

**URL:** <https://discourse.nodered.org/t/writing-functions-to-send-more-than-1-payload-and-topic/26775>\
**Category:** General\
**Created:** [16 May 2020 21:37 UTC](https://discourse.nodered.org/t/writing-functions-to-send-more-than-1-payload-and-topic/26775 "2020-05-16T21:37:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chenko](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@Chenko](https://discourse.nodered.org/u/Chenko)\
**Post date:** [16 May 2020 21:37 UTC](https://discourse.nodered.org/t/writing-functions-to-send-more-than-1-payload-and-topic/26775/1 "2020-05-16T21:37:17Z")

</div>

Hello  
I just started using node red and i have this challenge, i want to write a function that can pass more than on payload and topic. Please anyone help with explanations, and ways forward.

---

<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:** [16 May 2020 21:47 UTC](https://discourse.nodered.org/t/writing-functions-to-send-more-than-1-payload-and-topic/26775/2 "2020-05-16T21:47:42Z")

</div>

Hi @Chenko

the docs cover how to send multiple messages: [https://nodered.org/docs/user-guide/writing-functions#multiple-messages](https://nodered.org/docs/user-guide/writing-functions#multiple-messages)

---

<div class="post-metadata">

**Author:** ![Chenko](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@Chenko](https://discourse.nodered.org/u/Chenko)\
**Post date:** [17 May 2020 05:18 UTC](https://discourse.nodered.org/t/writing-functions-to-send-more-than-1-payload-and-topic/26775/3 "2020-05-17T05:18:59Z")

</div>

Hi knolleary  
Thank you i have red through the document. I will try to understand it

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 May 2020 06:38 UTC](https://discourse.nodered.org/t/writing-functions-to-send-more-than-1-payload-and-topic/26775/4 "2020-05-17T06:38:34Z")

</div>

Do you mean you want to send multiple messages, or that you want to send one message but with more in it than payload and topic? If the latter then in a function node you can say  
`msg.someAttribute = something`  
You can also do that with a Change node.  
As well as the link suggested look at the page on Working with Messages.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [17 May 2020 10:17 UTC](https://discourse.nodered.org/t/writing-functions-to-send-more-than-1-payload-and-topic/26775/5 "2020-05-17T10:17:19Z")

</div>

Hi @Chenko

Here is a little function that sends multiple msg's. I don't know what your inputs are but I hope this helps you figure a method.

```auto
var IPS = msg.payload.ip.split("|");
var TOPIC = msg.payload.message.split("|");
for (var i in IPS) { 
msg.payload = {"ip": IPS[i]};
msg.topic = TOPIC[i];
node.send(msg);
}
return;

```

```auto
msg.payload = "1.1.1.1|2.2.2.2|.3.3.3.3"
msg.topic = "topic1|topic2|topic3"

```

This will send multipe messages (3)  
`{"msg", {"payload":{"ip": "1.1.1.1"}, "topic": "topic1"}}`

---

<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:** [31 May 2020 10:17 UTC](https://discourse.nodered.org/t/writing-functions-to-send-more-than-1-payload-and-topic/26775/6 "2020-05-31T10:17:20Z")

</div>

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