Join into an array... How to pass into the same place every time

I'm moving values from the JSON nodes into an array but they seem to come through in an uncertain order. Is there a way to make sure the same node moves its value into the same place in the array every time?

[
    {
        "id": "cd97b652011b3194",
        "type": "json",
        "z": "f818e70d04de7231",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 870,
        "y": 760,
        "wires": [
            [
                "77f71195666e5cde"
            ]
        ]
    },
    {
        "id": "8ca5f8b66f1a49b6",
        "type": "http in",
        "z": "f818e70d04de7231",
        "name": "",
        "url": "a",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 170,
        "y": 780,
        "wires": [
            [
                "59cbc5672c44b899",
                "6cfd30233baac18c",
                "b3daa3897de2cd84",
                "6ae4c2b4eca2b6a3",
                "4ebccf086882b47a",
                "4e39cef70cad66a0",
                "743ee07924c09fb5",
                "938f781def71e5da"
            ]
        ]
    },
    {
        "id": "e4b08ea88cbc34a2",
        "type": "http response",
        "z": "f818e70d04de7231",
        "name": "",
        "statusCode": "200",
        "headers": {
            "content-type": "text/html"
        },
        "x": 1560,
        "y": 920,
        "wires": []
    },
    {
        "id": "d8ded07f12cffaa0",
        "type": "json",
        "z": "f818e70d04de7231",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 870,
        "y": 820,
        "wires": [
            [
                "77f71195666e5cde"
            ]
        ]
    },
    {
        "id": "3b00fddcc2006cd2",
        "type": "json",
        "z": "f818e70d04de7231",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 870,
        "y": 880,
        "wires": [
            [
                "77f71195666e5cde"
            ]
        ]
    },
    {
        "id": "77f71195666e5cde",
        "type": "join",
        "z": "f818e70d04de7231",
        "name": "",
        "mode": "custom",
        "build": "array",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "8",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 1090,
        "y": 920,
        "wires": [
            [
                "3e971cfe0f70f389",
                "f3aa309b5130a48c"
            ]
        ]
    },
    {
        "id": "f3aa309b5130a48c",
        "type": "function",
        "z": "f818e70d04de7231",
        "name": "function 2",
        "func": "// Retrieve the values from the array\nconst [value1, value2, value3] = msg.payload;\n\n// Round the values to 2 decimal places\nconst Value1 = Number(value1).toFixed(0);\nconst Value2 = Number(value2).toFixed(0);\nconst Value3 = Number(value3).toFixed(0);\n\n// Set the rounded values to be used in the template node\nmsg.payload = {\n    \"value1\": Value1,\n    \"value2\": Value2,\n    \"value3\": Value3\n};\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1240,
        "y": 920,
        "wires": [
            [
                "5ee6bb4a19739f1a"
            ]
        ]
    },
    {
        "id": "5ee6bb4a19739f1a",
        "type": "template",
        "z": "f818e70d04de7231",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "<!DOCTYPE html>\n<html>\n\n<head>\n  <title>Displaying 10 really big</title>\n  <style>\n    /* Import the Montserrat font from Google Fonts */\n    @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap');\n\n    .big-number {\n      font-family: 'Montserrat', sans-serif;\n      /* Set the font to Montserrat */\n      font-size: 10rem;\n      font-weight: bold;\n      text-align: center;\n      margin-top: 100px;\n      color: #27ae60;\n      text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);\n    }\n\n    .assembly-line {\n      font-family: 'Montserrat', sans-serif;\n      /* Set the font to Montserrat */\n      font-size: 1.5rem;\n      /* Set the font size to be smaller */\n      font-weight: bold;\n      text-align: center;\n      color: black;\n    }\n\t\n\t\n\t.boxbottomtext {\n      font-family: 'Montserrat', sans-serif;\n      /* Set the font to Montserrat */\n      font-size: 1.5rem;\n      /* Set the font size to be smaller */\n      font-weight: bold;\n      text-align: center;\n      color: white;\n    }\n\t\n\t\n  </style>\n</head>\n\n<body>\n  \n\n  <div id=\"myChart\"></div> <!-- Add an element with the ID 'myChart' -->\n\n  <script language=\"javascript\">\n    setTimeout(function(){\n       window.location.reload(1);\n    }, 2000);\n  </script>\n\n  <script src=\"https://d3js.org/d3.v6.min.js\"></script>\n\n  <script>\n   var svg = d3.select(\"#myChart\")\n            .append(\"svg\")\n            .attr(\"width\", 400)\n            .attr(\"height\", 400)\n            .attr(\"id\", \"mySvg\"); // Add an ID to the SVG element\n/*\n    var circleColor = \"{{payload.value3}}\" === \"true\" ? \"green\" : \"red\"; // Set the color based on the value of payload.value3\n\n    svg.append(\"circle\")\n       .attr(\"cx\", 200)\n       .attr(\"cy\", 200)\n       .attr(\"r\", 100)\n       .attr(\"fill\", circleColor); // Use the color variable to set the fill color\n\t   \n\t   \n\t   var svg = d3.select(\"#myChart\")\n    .append(\"svg\")\n    .attr(\"width\", 400)\n    .attr(\"height\", 400);\n\t\n\t*/\t\n\nvar rect = svg.append(\"rect\")\n    .attr(\"x\", 150)\n    .attr(\"y\", 150)\n    .attr(\"width\", 400)\n    .attr(\"height\", 100)\n    .attr(\"fill\", function() {\n        if ({{payload.value3}} == true) {\n            return \"green\";\n        } else {\n            return \"red\";\n        }\n    });\n\t\nvar text = svg.append(\"text\")\n        .classed(\"boxbottomtext\", true)\n        .attr(\"x\", 200)\n        .attr(\"y\", 200)\n        .attr(\"text-anchor\", \"middle\")\n        .attr(\"dominant-baseline\", \"middle\")\n        .text({{payload.value3}} ? \"RUNNING\" : \"STOPPED\");\n\n\n  </script>\n  \n  \n<div class=\"big-number\" id=\"big-number\">{{payload.value1}}</div>\n  <div class=\"big-number\" id=\"big-number\">{{payload.value2}}</div>\n  <div class=\"big-number\" id=\"big-number\">{{payload.value3}}</div>\n  <div class=\"assembly-line\">ASSEMBLY LINE E</div>\n</body>\n\n</html>\n\n\n\n\n",
        "output": "str",
        "x": 1400,
        "y": 920,
        "wires": [
            [
                "e4b08ea88cbc34a2"
            ]
        ]
    },
    {
        "id": "59cbc5672c44b899",
        "type": "OpcUa-Item",
        "z": "f818e70d04de7231",
        "item": "ns=2;s=BAR-LIN-LINEH.PLC.CycleCount",
        "datatype": "Int32",
        "value": "",
        "name": "Line H Count",
        "x": 370,
        "y": 700,
        "wires": [
            [
                "27c3b28115eae0a1"
            ]
        ]
    },
    {
        "id": "27c3b28115eae0a1",
        "type": "OpcUa-Client",
        "z": "f818e70d04de7231",
        "endpoint": "7290d8b0.f713d8",
        "action": "read",
        "deadbandvalue": "",
        "time": "5",
        "timeUnit": "s",
        "localfile": "",
        "localkeyfile": "",
        "folderName4PKI": "",
        "name": "Test server (subscribe items)",
        "x": 620,
        "y": 700,
        "wires": [
            [
                "5879ef033770e553"
            ]
        ]
    },
    {
        "id": "6cfd30233baac18c",
        "type": "OpcUa-Item",
        "z": "f818e70d04de7231",
        "item": "ns=2;s=BAR-LIN-LINEG.PLC.CycleCount",
        "datatype": "Int32",
        "value": "",
        "name": "Line G Count",
        "x": 370,
        "y": 760,
        "wires": [
            [
                "2b2f1a74949e8a15"
            ]
        ]
    },
    {
        "id": "2b2f1a74949e8a15",
        "type": "OpcUa-Client",
        "z": "f818e70d04de7231",
        "endpoint": "7290d8b0.f713d8",
        "action": "read",
        "deadbandvalue": "",
        "time": "5",
        "timeUnit": "s",
        "localfile": "",
        "localkeyfile": "",
        "folderName4PKI": "",
        "name": "Test server (subscribe items)",
        "x": 620,
        "y": 760,
        "wires": [
            [
                "cd97b652011b3194"
            ]
        ]
    },
    {
        "id": "b3daa3897de2cd84",
        "type": "OpcUa-Item",
        "z": "f818e70d04de7231",
        "item": "ns=2;s=BAR-LIN-LINEF.PLC.CycleCount",
        "datatype": "Int32",
        "value": "",
        "name": "Line F Count",
        "x": 370,
        "y": 820,
        "wires": [
            [
                "996a93e370e41fbc"
            ]
        ]
    },
    {
        "id": "996a93e370e41fbc",
        "type": "OpcUa-Client",
        "z": "f818e70d04de7231",
        "endpoint": "7290d8b0.f713d8",
        "action": "read",
        "deadbandvalue": "",
        "time": "5",
        "timeUnit": "s",
        "localfile": "",
        "localkeyfile": "",
        "folderName4PKI": "",
        "name": "Test server (subscribe items)",
        "x": 620,
        "y": 820,
        "wires": [
            [
                "d8ded07f12cffaa0"
            ]
        ]
    },
    {
        "id": "5879ef033770e553",
        "type": "json",
        "z": "f818e70d04de7231",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 870,
        "y": 700,
        "wires": [
            [
                "77f71195666e5cde"
            ]
        ]
    },
    {
        "id": "4ebccf086882b47a",
        "type": "OpcUa-Item",
        "z": "f818e70d04de7231",
        "item": "ns=2;s=BAR-LIN-LINEE.PLC.CycleCount",
        "datatype": "Int32",
        "value": "",
        "name": "Line E Count",
        "x": 370,
        "y": 880,
        "wires": [
            [
                "1fa7137ce2f0ef47"
            ]
        ]
    },
    {
        "id": "1fa7137ce2f0ef47",
        "type": "OpcUa-Client",
        "z": "f818e70d04de7231",
        "endpoint": "7290d8b0.f713d8",
        "action": "read",
        "deadbandvalue": "",
        "time": "5",
        "timeUnit": "s",
        "localfile": "",
        "localkeyfile": "",
        "folderName4PKI": "",
        "name": "Test server (subscribe items)",
        "x": 620,
        "y": 880,
        "wires": [
            [
                "3b00fddcc2006cd2"
            ]
        ]
    },
    {
        "id": "6ae4c2b4eca2b6a3",
        "type": "OpcUa-Item",
        "z": "f818e70d04de7231",
        "item": "ns=2;s=BAR-LIN-LINEE.PLC.Status",
        "datatype": "UInt16",
        "value": "",
        "name": "Line E Status",
        "x": 370,
        "y": 1160,
        "wires": [
            [
                "0de625764d428a74"
            ]
        ]
    },
    {
        "id": "0de625764d428a74",
        "type": "OpcUa-Client",
        "z": "f818e70d04de7231",
        "endpoint": "7290d8b0.f713d8",
        "action": "read",
        "deadbandvalue": "",
        "time": "5",
        "timeUnit": "s",
        "localfile": "",
        "localkeyfile": "",
        "folderName4PKI": "",
        "name": "Test server (subscribe items)",
        "x": 620,
        "y": 1160,
        "wires": [
            [
                "cfb68065e3ab5ad1"
            ]
        ]
    },
    {
        "id": "938f781def71e5da",
        "type": "OpcUa-Item",
        "z": "f818e70d04de7231",
        "item": "ns=2;s=BAR-LIN-LINEF.PLC.Status",
        "datatype": "UInt16",
        "value": "",
        "name": "Line F Status",
        "x": 370,
        "y": 1100,
        "wires": [
            [
                "5b29f5bad43f35cf"
            ]
        ]
    },
    {
        "id": "5b29f5bad43f35cf",
        "type": "OpcUa-Client",
        "z": "f818e70d04de7231",
        "endpoint": "7290d8b0.f713d8",
        "action": "read",
        "deadbandvalue": "",
        "time": "5",
        "timeUnit": "s",
        "localfile": "",
        "localkeyfile": "",
        "folderName4PKI": "",
        "name": "Test server (subscribe items)",
        "x": 620,
        "y": 1100,
        "wires": [
            [
                "40921b4eb67536fe"
            ]
        ]
    },
    {
        "id": "743ee07924c09fb5",
        "type": "OpcUa-Item",
        "z": "f818e70d04de7231",
        "item": "ns=2;s=BAR-LIN-LINEG.PLC.Status",
        "datatype": "UInt16",
        "value": "",
        "name": "Line G Status",
        "x": 380,
        "y": 1040,
        "wires": [
            [
                "c5f2c82e45874619"
            ]
        ]
    },
    {
        "id": "c5f2c82e45874619",
        "type": "OpcUa-Client",
        "z": "f818e70d04de7231",
        "endpoint": "7290d8b0.f713d8",
        "action": "read",
        "deadbandvalue": "",
        "time": "5",
        "timeUnit": "s",
        "localfile": "",
        "localkeyfile": "",
        "folderName4PKI": "",
        "name": "Test server (subscribe items)",
        "x": 620,
        "y": 1040,
        "wires": [
            [
                "d2cd44d5ed3d44b9"
            ]
        ]
    },
    {
        "id": "4e39cef70cad66a0",
        "type": "OpcUa-Item",
        "z": "f818e70d04de7231",
        "item": "ns=2;s=BAR-LIN-LINEH.PLC.Status",
        "datatype": "UInt16",
        "value": "",
        "name": "Line H Status",
        "x": 380,
        "y": 980,
        "wires": [
            [
                "d76090bef0a93e2b"
            ]
        ]
    },
    {
        "id": "d76090bef0a93e2b",
        "type": "OpcUa-Client",
        "z": "f818e70d04de7231",
        "endpoint": "7290d8b0.f713d8",
        "action": "read",
        "deadbandvalue": "",
        "time": "5",
        "timeUnit": "s",
        "localfile": "",
        "localkeyfile": "",
        "folderName4PKI": "",
        "name": "Test server (subscribe items)",
        "x": 620,
        "y": 980,
        "wires": [
            [
                "9a0bb4577a31b3b4"
            ]
        ]
    },
    {
        "id": "d2cd44d5ed3d44b9",
        "type": "json",
        "z": "f818e70d04de7231",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 870,
        "y": 1040,
        "wires": [
            [
                "77f71195666e5cde"
            ]
        ]
    },
    {
        "id": "40921b4eb67536fe",
        "type": "json",
        "z": "f818e70d04de7231",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 870,
        "y": 1100,
        "wires": [
            [
                "77f71195666e5cde"
            ]
        ]
    },
    {
        "id": "cfb68065e3ab5ad1",
        "type": "json",
        "z": "f818e70d04de7231",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 870,
        "y": 1160,
        "wires": [
            [
                "77f71195666e5cde"
            ]
        ]
    },
    {
        "id": "9a0bb4577a31b3b4",
        "type": "json",
        "z": "f818e70d04de7231",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 870,
        "y": 980,
        "wires": [
            [
                "77f71195666e5cde"
            ]
        ]
    },
    {
        "id": "3e971cfe0f70f389",
        "type": "debug",
        "z": "f818e70d04de7231",
        "name": "debug 5",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1200,
        "y": 660,
        "wires": []
    },
    {
        "id": "7290d8b0.f713d8",
        "type": "OpcUa-Endpoint",
        "endpoint": "opc.tcp://10.50.66.175:49320",
        "none": false,
        "login": false,
        "usercert": false,
        "usercertificate": "",
        "userprivatekey": ""
    }
]

Could you sort the array on a particular column of the array?

Join as key/value object, then you can use the object to create the array, guaranteeing the array order.
Example, the split values have a random delay, so can not guarantee the delivery order.
Joining them as object, then using template to guarantee the order.

[{"id":"a717f8645c06d878","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"one\":1,\"two\":2,\"three\":3}","payloadType":"json","x":470,"y":4560,"wires":[["c3b9bbf9f5ac4007"]]},{"id":"c3b9bbf9f5ac4007","type":"split","z":"65617ffeb779f51c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":670,"y":4560,"wires":[["4b592f2367138ff7"]]},{"id":"4b592f2367138ff7","type":"delay","z":"65617ffeb779f51c","name":"","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":800,"y":4560,"wires":[["900b6933ebe52568","b297b79cdbcc6f7c"]]},{"id":"900b6933ebe52568","type":"join","z":"65617ffeb779f51c","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":510,"y":4660,"wires":[["ac893f12ba0b88b1"]]},{"id":"b297b79cdbcc6f7c","type":"debug","z":"65617ffeb779f51c","name":"debug 250","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":4660,"wires":[]},{"id":"ac893f12ba0b88b1","type":"template","z":"65617ffeb779f51c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"[\n{{payload.one}},\n{{payload.two}},\n{{payload.three}}\n]","output":"json","x":660,"y":4660,"wires":[["b297b79cdbcc6f7c"]]}]
1 Like

Thankyou so much. I love the example, shows it perfectly!

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