Using array loop

#1

Hello,

I'm new to node red. I'm trying to change some examples to my use. I have imported https://github.com/s1r-J/node-red-contrib-loop-processing

Now i want to put in a array through a array loop. But after 1 cycle i'm getting an error: Array not a array. I have added he flow. Maybe my expectation of the loop is not correct , but i hoped that with the array loop i could alter each value of the array per cycle

[{"id":"43b9794b.d417a8","type":"array-loop","z":"6e33f310.386c04","name":"array loop","key":"al43b9794bd417a8","keyType":"msg","array":"payload","arrayType":"msg","x":830,"y":1040,"wires":[["97bd213e.0ba2e"],["fa8df784.f29598"]]},{"id":"97bd213e.0ba2e","type":"debug","z":"6e33f310.386c04","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"array","x":1030,"y":1060,"wires":[]},{"id":"fa8df784.f29598","type":"function","z":"6e33f310.386c04","name":"return msg","func":"var payload = msg.payload\n\nmsg.payload = payload;\n \nreturn msg;","outputs":1,"noerr":0,"x":1010,"y":1180,"wires":[["b8f0ceb2.275328","43b9794b.d417a8"]]},{"id":"b8f0ceb2.275328","type":"debug","z":"6e33f310.386c04","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1220,"y":1180,"wires":[]},{"id":"96e33b30.3072e8","type":"inject","z":"6e33f310.386c04","name":"","topic":"","payload":"[\"tag:profiles.ibm.com,2006:entry005a1bd3-f598-4897-ad39-3e18650ba261\",\"tag:profiles.ibm.com,2006:entry00d49028-a7e5-4b64-b009-7e7b4378acea\",\"tag:profiles.ibm.com,2006:entry0107736a-6ef3-4d21-afbb-7e81f6505182\",\"tag:profiles.ibm.com,2006:entry0149088a-57f6-47f3-924d-c6901dc490db\",\"tag:profiles.ibm.com,2006:entry0166d610-7cce-4735-9382-d71c785e6a34\",\"tag:profiles.ibm.com,2006:entry034ba4c8-b18a-482b-8bdf-0bcc9289526e\",\"tag:profiles.ibm.com,2006:entry03b0df19-8009-476c-8d35-0a4cb941bed2\",\"tag:profiles.ibm.com,2006:entry04462d96-1202-4d0b-a628-fa880bc60266\",\"tag:profiles.ibm.com,2006:entry0483fa81-86ec-4bac-8086-b33225e79d01\",\"tag:profiles.ibm.com,2006:entry05178261-d2dc-4561-863a-5bced05c7250\"]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":450,"y":1040,"wires":[["43b9794b.d417a8","92e6c928.9734e"]]},{"id":"92e6c928.9734e","type":"debug","z":"6e33f310.386c04","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":1100,"wires":[]}]
0 Likes

#2

Hi,

please read this post about sharing code/flows on the forum - How to share code or flow json

Which node modules are you using? array-loop isn't a core node so must have come from a contrib module.

0 Likes

#3

Hi ,
I have edited the code, correctly now. Sorry about that
Indeed array-loop is a contrib module

0 Likes

#4

I stopped using the array-loop. And followed another example that works for me.

[{"id":"82e0d8a5.ca2f28","type":"inject","z":"6e33f310.386c04","name":"","topic":"","payload":"[\"tag:profiles.ibm.com,2006:entry005a1bd3-f598-4897-ad39-3e18650ba261\",\"tag:profiles.ibm.com,2006:entry00d49028-a7e5-4b64-b009-7e7b4378acea\",\"tag:profiles.ibm.com,2006:entry0107736a-6ef3-4d21-afbb-7e81f6505182\",\"tag:profiles.ibm.com,2006:entry0149088a-57f6-47f3-924d-c6901dc490db\",\"tag:profiles.ibm.com,2006:entry0166d610-7cce-4735-9382-d71c785e6a34\",\"tag:profiles.ibm.com,2006:entry034ba4c8-b18a-482b-8bdf-0bcc9289526e\",\"tag:profiles.ibm.com,2006:entry03b0df19-8009-476c-8d35-0a4cb941bed2\",\"tag:profiles.ibm.com,2006:entry04462d96-1202-4d0b-a628-fa880bc60266\",\"tag:profiles.ibm.com,2006:entry0483fa81-86ec-4bac-8086-b33225e79d01\",\"tag:profiles.ibm.com,2006:entry05178261-d2dc-4561-863a-5bced05c7250\"]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":430,"y":1500,"wires":[["3cc05f17.e55ea","3c965cca.bf47ec"]]},{"id":"3cc05f17.e55ea","type":"debug","z":"6e33f310.386c04","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":470,"y":1560,"wires":[]},{"id":"e87a08d5.d44eb8","type":"debug","z":"6e33f310.386c04","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1030,"y":1500,"wires":[]},{"id":"3c965cca.bf47ec","type":"function","z":"6e33f310.386c04","name":"array loop","func":"var msgList = [];\nvar letterList = msg.payload;\nfor (var i =0 ; i < 10; i++){\n    msgList.push({payload:letterList[i]});\n}\nreturn [msgList];","outputs":1,"noerr":0,"x":810,"y":1500,"wires":[["e87a08d5.d44eb8"]]}]


0 Likes