JOIN Node - Manual mode & Merged Object

Hi, I want to merge 2 payloads containing different fields into one with the JOIN node. I'm using the Manual mode to create a merged object. I'm facing strange through testing.

I've simplified my flow to this:

[{"id":"d28e2caa.c58df","type":"function","z":"73f2c6a9.b53548","name":"payload1","func":"msg = {\n    payload: {\n        correlationId: '012345',\n        trigger: 'trigger'\n    }\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":980,"wires":[["d6918015.cbf79","b5259e2.10e2c6"]]},{"id":"9e0f4a4e.6daf08","type":"function","z":"73f2c6a9.b53548","name":"payload2","func":"msg = {\n    payload: {\n        pictures: [\n            {\n                pictureName: '00_12_laserIn.jpeg',\n                camera:'12',\n                trigger:'laserIn'\n            },\n            {\n                pictureName: '00_13_laserOut.jpeg',\n                camera:'13',\n                trigger:'laserOut'\n            }\n        ]\n    }\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":1020,"wires":[["d6918015.cbf79","4746d0f4.b8a55"]]},{"id":"d6d1765d.d10a48","type":"inject","z":"73f2c6a9.b53548","name":"inject1","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":980,"wires":[["d28e2caa.c58df"]]},{"id":"d6918015.cbf79","type":"join","z":"73f2c6a9.b53548","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"payload","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":470,"y":1000,"wires":[["6fd97b52.2d1044"]]},{"id":"6fd97b52.2d1044","type":"debug","z":"73f2c6a9.b53548","name":"both","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":1000,"wires":[]},{"id":"a5d0c387.50b6","type":"inject","z":"73f2c6a9.b53548","name":"inject2","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":1020,"wires":[["9e0f4a4e.6daf08"]]},{"id":"4746d0f4.b8a55","type":"debug","z":"73f2c6a9.b53548","name":"down","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":470,"y":1040,"wires":[]},{"id":"b5259e2.10e2c6","type":"debug","z":"73f2c6a9.b53548","name":"up","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":470,"y":960,"wires":[]}]

join_node_manual_merged

payload1:

msg = {
    payload: {
        correlationId: '012345',
        trigger: 'trigger'
    }
};

payload2:

msg = {
    payload: {
        pictures: [
            {
                pictureName: '00_12_laserIn.jpeg',
                camera:'12',
                trigger:'laserIn'
            },
            {
                pictureName: '00_13_laserOut.jpeg',
                camera:'13',
                trigger:'laserOut'
            }
        ]
    }
};

Expected Result:

msg = {
    payload: {
        correlationId: '012345',
        trigger: 'trigger',
        pictures: [
            {
                pictureName: '00_12_laserIn.jpeg',
                camera:'12',
                trigger:'laserIn'
            },
            {
                pictureName: '00_13_laserOut.jpeg',
                camera:'13',
                trigger:'laserOut'
            }
        ]
    }
};

Tests:

  • Fire inject1 only => Debug logs 'up' and 'both' => 'both' contains only payload1 --KO--
  • Fire inject2 only => Debug logs 'down' only --OK--
  • Fire inject1 and then inject2 => Debug logs 'up' then 'both then 'down' => 'both' contains only payload1 --KO--
  • Fire inject2 and then inject1 => Debug logs 'down' then 'up' then 'both' => 'both' contains the expected result --OK--

Issues:

  • Why log 'both' is always logged when inject1 is fired?
  • How can I have the expected result

Thank you for your help

Node-RED version: 1.0.3

Hi @soma

The message from inject1 has 2 properties. The message from inject2 has 1 property. So in total, you have 3 properties to join. However, your Join node is configured to wait for 2 message parts - hence the unexpected result.

If you change it to 3, it does what you want.

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