# Join, Getting order incorrect sometimes

**URL:** https://discourse.nodered.org/t/join-getting-order-incorrect-sometimes/20331
**Category:** General
**Created:** [14 January 2020 20:10 UTC](https://discourse.nodered.org/t/join-getting-order-incorrect-sometimes/20331 "2020-01-14T20:10:13Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![ScheepersJohan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scheepersjohan/32/39556_2.png) [@ScheepersJohan](https://discourse.nodered.org/u/ScheepersJohan)
#### Post date: [14 January 2020 20:10 UTC](https://discourse.nodered.org/t/join-getting-order-incorrect-sometimes/20331/1 "2020-01-14T20:10:13Z")

</div>

Hi,

I have several payloads I need to joint to form a string, I have a very long winded way and it is cumbersome, how do I stream line it?

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

As sometimes the order gets muddled up.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8d7b34201dd6d8a65d1ecc28a888bb7ab426eeeb.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f678f15369f5ed1b1acfdc8ec3f8ed6a0b284ea2.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/d/0de816e24c8f52aadae7435212ba0914a4cc608a.png)

---

<div class="post-metadata">

### Author: ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)
#### Post date: [14 January 2020 20:19 UTC](https://discourse.nodered.org/t/join-getting-order-incorrect-sometimes/20331/2 "2020-01-14T20:19:48Z")

</div>

You really need to share your flow for a decent answer.

---

<div class="post-metadata">

### Author: ![ScheepersJohan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scheepersjohan/32/39556_2.png) [@ScheepersJohan](https://discourse.nodered.org/u/ScheepersJohan)
#### Post date: [15 January 2020 04:51 UTC](https://discourse.nodered.org/t/join-getting-order-incorrect-sometimes/20331/3 "2020-01-15T04:51:04Z")

</div>

```auto
[{"id":"35b73a03.2ff426","type":"tab","label":"Flow 9","disabled":false,"info":""},{"id":"54be287.c469cd8","type":"inject","z":"35b73a03.2ff426","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"0 6-17 * * *","once":false,"onceDelay":0.1,"x":180,"y":220,"wires":[["199cbab1.1f3665"]]},{"id":"f5af2bc6.2c73d8","type":"change","z":"35b73a03.2ff426","name":"","rules":[{"t":"set","p":"number","pt":"msg","to":"payload","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":560,"wires":[["fe5ea807.1433b8"]]},{"id":"255ebbbb.6f8da4","type":"sensor-ds18b20","z":"35b73a03.2ff426","name":"","topic":"","sensorid":"28-000006c7f31d","timer":"21600","repeat":true,"x":400,"y":460,"wires":[["54faa4ed.25266c","2bce2f69.7248"]]},{"id":"fe5ea807.1433b8","type":"debug","z":"35b73a03.2ff426","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1020,"y":680,"wires":[]},{"id":"f510b7f1.f10d38","type":"function","z":"35b73a03.2ff426","name":"Temp 1: Grey\"","func":"msg.payload = \"Temp 1: Grey: \";\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":340,"wires":[["1b9edb33.6c7945","54faa4ed.25266c"]]},{"id":"1b9edb33.6c7945","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":400,"y":400,"wires":[["255ebbbb.6f8da4"]]},{"id":"c1db60d7.a07df","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":380,"y":640,"wires":[["e4051a8a.06c118"]]},{"id":"e4051a8a.06c118","type":"function","z":"35b73a03.2ff426","name":"Temp 2: Black","func":"msg.payload = \"Temp 2: Black: \";\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":700,"wires":[["f64f1208.997de","d4ee2a3d.279998"]]},{"id":"84499cc8.162ed","type":"sensor-ds18b20","z":"35b73a03.2ff426","name":"","topic":"","sensorid":"28-02131a935faa","timer":"21600","repeat":false,"x":360,"y":820,"wires":[["d4ee2a3d.279998","a8972d7f.a2c8e"]]},{"id":"6c9f9474.6cad0c","type":"join","z":"35b73a03.2ff426","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"Office","reduceInitType":"str","reduceFixup":"","x":660,"y":1220,"wires":[["52781460.83607c"]]},{"id":"c7bc6a6a.292038","type":"sensor-ds18b20","z":"35b73a03.2ff426","name":"","topic":"","sensorid":"28-000006c88310","timer":"21600","repeat":false,"x":340,"y":1180,"wires":[["70b6d292.630dbc","6c9f9474.6cad0c"]]},{"id":"b0b3d691.a15bc8","type":"function","z":"35b73a03.2ff426","name":"Temp 2: Grey 2\"","func":"msg.payload = \"Temp 2: Grey 2: \";\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":1060,"wires":[["caa34f08.5e67","6c9f9474.6cad0c"]]},{"id":"a8972d7f.a2c8e","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":360,"y":880,"wires":[["3b8746a5.4d84aa"]]},{"id":"f64f1208.997de","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":360,"y":760,"wires":[["84499cc8.162ed"]]},{"id":"caa34f08.5e67","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":340,"y":1120,"wires":[["c7bc6a6a.292038"]]},{"id":"d9d6043c.3b8f88","type":"function","z":"35b73a03.2ff426","name":"°C","func":"msg.payload = \" °C\";\nreturn msg;","outputs":1,"noerr":0,"x":380,"y":580,"wires":[["54faa4ed.25266c","c1db60d7.a07df"]]},{"id":"3b8746a5.4d84aa","type":"function","z":"35b73a03.2ff426","name":"°C","func":"msg.payload = \" °C\";\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":940,"wires":[["d4ee2a3d.279998","a788e2b8.5cacc"]]},{"id":"107a959a.828eda","type":"function","z":"35b73a03.2ff426","name":"°C","func":"msg.payload = \" °C\";\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":1300,"wires":[["6c9f9474.6cad0c"]]},{"id":"199cbab1.1f3665","type":"function","z":"35b73a03.2ff426","name":"Office","func":"msg.payload = \"Office\";\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":220,"wires":[["11cb63cd.4c287c","52781460.83607c"]]},{"id":"54faa4ed.25266c","type":"join","z":"35b73a03.2ff426","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"Office","reduceInitType":"str","reduceFixup":"","x":650,"y":500,"wires":[["52781460.83607c"]]},{"id":"d4ee2a3d.279998","type":"join","z":"35b73a03.2ff426","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"Office","reduceInitType":"str","reduceFixup":"","x":630,"y":860,"wires":[["52781460.83607c"]]},{"id":"52781460.83607c","type":"join","z":"35b73a03.2ff426","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"Office","reduceInitType":"str","reduceFixup":"","x":830,"y":460,"wires":[["f5af2bc6.2c73d8"]]},{"id":"11cb63cd.4c287c","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":400,"y":280,"wires":[["f510b7f1.f10d38"]]},{"id":"2bce2f69.7248","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":400,"y":520,"wires":[["d9d6043c.3b8f88"]]},{"id":"70b6d292.630dbc","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":340,"y":1240,"wires":[["107a959a.828eda"]]},{"id":"a788e2b8.5cacc","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":340,"y":1000,"wires":[["b0b3d691.a15bc8"]]}]

```

---

<div class="post-metadata">

### Author: ![ScheepersJohan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scheepersjohan/32/39556_2.png) [@ScheepersJohan](https://discourse.nodered.org/u/ScheepersJohan)
#### Post date: [22 January 2020 20:34 UTC](https://discourse.nodered.org/t/join-getting-order-incorrect-sometimes/20331/4 "2020-01-22T20:34:10Z")

</div>

Any body perhaps have some ideas for me as the join don't always get the order correct.

The messages below are all from the flow in my first post, the order jumps around.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/badd24dad32ac53592316fcd68e97334c3a5cf70.png)

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [22 January 2020 21:02 UTC](https://discourse.nodered.org/t/join-getting-order-incorrect-sometimes/20331/5 "2020-01-22T21:02:30Z")

</div>

What is the end result you are tying to achieve?

---

<div class="post-metadata">

### Author: ![ScheepersJohan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scheepersjohan/32/39556_2.png) [@ScheepersJohan](https://discourse.nodered.org/u/ScheepersJohan)
#### Post date: [22 January 2020 21:04 UTC](https://discourse.nodered.org/t/join-getting-order-incorrect-sometimes/20331/6 "2020-01-22T21:04:29Z")

</div>

I always want it to be in the same order, but it's not always.

This is what I want ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/27dae742e88cfc0510ee468397279305de93ffa5.png)

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [22 January 2020 21:41 UTC](https://discourse.nodered.org/t/join-getting-order-incorrect-sometimes/20331/7 "2020-01-22T21:41:40Z")

</div>

Have you read this ([https://nodered.org/docs/user-guide/messages#message-sequences](https://nodered.org/docs/user-guide/messages#message-sequences)) in the documentation?

Also, why not just build the message as you go along?

---

<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: [22 January 2020 22:44 UTC](https://discourse.nodered.org/t/join-getting-order-incorrect-sometimes/20331/8 "2020-01-22T22:44:29Z")

</div>

Hi @ScheepersJohan

Are the Delay nodes there just to try to get the ordering right? If so, you don't need them and you can  
simplify the flow considerably.

I would do something like the following: (the flow json for this is shared at the end of this post)

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

The three `DS18b20` nodes on the left are placeholders for your real `sensor-ds18b20` that I don't have installed locally.

The flow gets a reading from the first sensor node, then the change node moves its value to `msg.temp1`. It then gets the next reading and then moves that to `msg.temp2` and then the third reading is captured and moved to `msg.temp3`. The message then passes to the Template node, that contains the template:

```auto
Office
Temp1: Grey: {{temp1}} °C
Temp2: Black: {{temp2}} °C
Temp2: Grey 2: {{temp3}} °C

```

The other piece of feedback is your flow is using a lot of Function nodes just to set `msg.payload` to a fixed String value. I'd recommend getting into the habit of using the Change node for that sort of thing.

Here's the JSON:

```auto
[{"id":"a9963da1.09f22","type":"inject","z":"c3c543df.668ac","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"0 6-17 * * *","once":false,"onceDelay":0.1,"x":330,"y":60,"wires":[["ba8dfd35.9e54d"]]},{"id":"ba8dfd35.9e54d","type":"function","z":"c3c543df.668ac","name":"DS18b20","func":"\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":60,"wires":[["88dc9348.e89ce"]]},{"id":"88dc9348.e89ce","type":"change","z":"c3c543df.668ac","name":"Move payload to temp1","rules":[{"t":"move","p":"payload","pt":"msg","to":"temp1","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":60,"wires":[["b21ddcf4.09ad6"]]},{"id":"b21ddcf4.09ad6","type":"function","z":"c3c543df.668ac","name":"DS18b20","func":"\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":120,"wires":[["4b2bac19.f93eb4"]]},{"id":"4b2bac19.f93eb4","type":"change","z":"c3c543df.668ac","name":"Move payload to temp2","rules":[{"t":"move","p":"payload","pt":"msg","to":"temp2","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":120,"wires":[["4445bc16.cfa924"]]},{"id":"4445bc16.cfa924","type":"function","z":"c3c543df.668ac","name":"DS18b20","func":"\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":180,"wires":[["fd51b008.d226f"]]},{"id":"fd51b008.d226f","type":"change","z":"c3c543df.668ac","name":"Move payload to temp3","rules":[{"t":"move","p":"payload","pt":"msg","to":"temp3","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":180,"wires":[["84cb690e.2ca0d8"]]},{"id":"84cb690e.2ca0d8","type":"template","z":"c3c543df.668ac","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Office\nTemp1: Grey: {{temp1}} °C\nTemp2: Black: {{temp2}} °C\nTemp2: Grey 2: {{temp3}} °C","output":"str","x":980,"y":180,"wires":[["95520998.2e2328"]]},{"id":"95520998.2e2328","type":"debug","z":"c3c543df.668ac","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1150,"y":180,"wires":[]}]

```
