# Dealing with multiple msg.payloads at once

**URL:** <https://discourse.nodered.org/t/dealing-with-multiple-msg-payloads-at-once/31322>\
**Category:** General\
**Created:** [8 August 2020 19:39 UTC](https://discourse.nodered.org/t/dealing-with-multiple-msg-payloads-at-once/31322 "2020-08-08T19:39:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikewoodld](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikewoodld/32/26822_2.png) [@mikewoodld](https://discourse.nodered.org/u/mikewoodld)\
**Post date:** [8 August 2020 19:39 UTC](https://discourse.nodered.org/t/dealing-with-multiple-msg-payloads-at-once/31322/1 "2020-08-08T19:39:37Z")

</div>

Hi! I'm wondering if there's a more efficient way to accomplish what I'm doing here.

I'm using the FlightRadar24 Node, and the goal is that I want to generate a return-separated list of all of the flight registration numbers that it sees when activated.

Here's the flow that I made that accomplishes this, but I can't help but to think there's a more efficient way of doing it.

The challenge that I'm having is is that it returns each flight as its own msg.payload, rather than an object containing all of the flights.

```auto
[{"id":"e078e36c.5ea4d8","type":"tab","label":"FlightRadar24","disabled":false,"info":""},{"id":"847e74f7.1ff67","type":"flightradar24","z":"e078e36c.5ea4d8","lat":"34.129299","latType":"num","lon":"-88.640327","lonType":"num","name":"","x":390,"y":420,"wires":[["341310fb.aee5e","6492175.a155068"]]},{"id":"c9a0c1b4.a9f078","type":"inject","z":"e078e36c.5ea4d8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":260,"wires":[["c1a25886.0012b8"]]},{"id":"341310fb.aee5e","type":"debug","z":"e078e36c.5ea4d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":380,"wires":[]},{"id":"ce0e65b0.3f7748","type":"change","z":"e078e36c.5ea4d8","name":"","rules":[{"t":"set","p":"reglist","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":420,"wires":[[]]},{"id":"4eb68d95.03e6ac","type":"debug","z":"e078e36c.5ea4d8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1050,"y":380,"wires":[]},{"id":"c1a25886.0012b8","type":"change","z":"e078e36c.5ea4d8","name":"","rules":[{"t":"set","p":"reglist","pt":"flow","to":" ","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":340,"wires":[["847e74f7.1ff67"]]},{"id":"cbff6f12.04444","type":"function","z":"e078e36c.5ea4d8","name":"","func":"var reg = msg.payload.registration+\"\\n\"\nvar list = flow.get(\"reglist\")\n\nmsg.payload = reg+list\nreturn msg;","outputs":1,"noerr":0,"x":890,"y":420,"wires":[["ce0e65b0.3f7748","4eb68d95.03e6ac"]]},{"id":"6492175.a155068","type":"delay","z":"e078e36c.5ea4d8","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"20","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":600,"y":420,"wires":[["2155f826.78d03"]]},{"id":"2155f826.78d03","type":"switch","z":"e078e36c.5ea4d8","name":"no nulls","property":"msg.payload.registration","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":760,"y":420,"wires":[["cbff6f12.04444"]]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/1979f72f51a9e5db41d794712b70fb856ff69167.png)

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [8 August 2020 20:17 UTC](https://discourse.nodered.org/t/dealing-with-multiple-msg-payloads-at-once/31322/2 "2020-08-08T20:17:18Z")

</div>

Hi Mike, if you are posting code/flows in the forum, can you please put the 3 backtips before and after your code/flow on separate blank lines, as per [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506) otherwise other users may not be able to import it.

You can edit your post above by using the pencil icon.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [9 August 2020 04:12 UTC](https://discourse.nodered.org/t/dealing-with-multiple-msg-payloads-at-once/31322/3 "2020-08-09T04:12:03Z")

</div>

Do you want the flow.reglist to contain a string with all the flights ?

You can use a join node to combine the messages, see flow example

```auto
[{"id":"25cfb79.25362c8","type":"inject","z":"5e81d16f.2a00b","name":"","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":228,"y":408,"wires":[["f84b9b07.7d029"]]},{"id":"f2e42509.bcd9a","type":"switch","z":"5e81d16f.2a00b","name":"no nulls","property":"msg.payload.registration","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":408,"wires":[["f19a893d.91d3a"]]},{"id":"f84b9b07.7d029","type":"flightradar24","z":"5e81d16f.2a00b","lat":"51.463394","latType":"num","lon":"-0.457090","lonType":"num","name":"","x":382,"y":408,"wires":[["f2e42509.bcd9a"]]},{"id":"f19a893d.91d3a","type":"join","z":"5e81d16f.2a00b","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"2","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":674,"y":408,"wires":[["55892059.faab6","b573fde1.e4bd4"]]},{"id":"55892059.faab6","type":"debug","z":"5e81d16f.2a00b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":818,"y":384,"wires":[]},{"id":"b573fde1.e4bd4","type":"change","z":"5e81d16f.2a00b","name":"","rules":[{"t":"set","p":"reglist","pt":"flow","to":"**.registration","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":848,"y":432,"wires":[[]]}]

```

Note that i have set the lat/lon to London for some usable data (not much flying these days 😉 )  
`flow.reglist` will contain an array of flight registrations.

What is the end goal of this flow ?

---

<div class="post-metadata">

**Author:** ![mikewoodld](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikewoodld/32/26822_2.png) [@mikewoodld](https://discourse.nodered.org/u/mikewoodld)\
**Post date:** [9 August 2020 14:34 UTC](https://discourse.nodered.org/t/dealing-with-multiple-msg-payloads-at-once/31322/4 "2020-08-09T14:34:21Z")

</div>

Ah, a join node! I didn't even know those existed. This is exactly what I was looking for, thanks!

And as for end goal, not sure yet. I was just experimenting with the data for now. Perhaps one day adding nearby flights to my office status board, we'll see.

Thanks for your help!

---

<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:** [23 August 2020 14:34 UTC](https://discourse.nodered.org/t/dealing-with-multiple-msg-payloads-at-once/31322/5 "2020-08-23T14:34:22Z")

</div>

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