Hello.
I've tried to find a way to do what I'm looking for but can't seem to figure it out.
What i need to do is loop through "msg.payload.data.Nodes[1 through however many there are]" and search for key "Name" and Properties[0] or [1] Status.
I've created a short test for it.
The end goal is to save it as flow.set("Name","Status") from above, the "Node" can be anything from 1 through 154 at different times.
I've tried to sort it out in different ways, but the two things I'm coming closest to is something like this:
(Either of the two)
/*for (var key in msg.payload.data.Nodes){
var myObj = msg.payload.data.Nodes[key]
msg.obj2 += myObj
msg.test += key
msg.payload = myObj*/
for (const [key, value] of Object.entries(msg.payload.data.Nodes[1])){
msg.key += key
msg.val += value
}
return msg;
The msg.key/val etc is just for checking the outputs.
And as you can see in the top image, the first part always gets "undefined+key".
If I change the msg.val from += to = so I only get the last object, it's working
Test-flow:
[{"id":"a21d0ac1.37a3e8","type":"debug","z":"649a18f3.49a458","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1450,"y":460,"wires":[]},{"id":"b5700a0b.66f718","type":"function","z":"649a18f3.49a458","name":"","func":"/*for (var key in msg.payload){\n var myObj = msg.payload[key]\n \n msg.obj2 += myObj\nmsg.test += key\nmsg.payload = myObj*/\nfor (const [key, value] of Object.entries(msg.payload.data.Nodes[1])){\n msg.key += key \n msg.val += value\n \n }\n \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1120,"y":480,"wires":[["58948649.b189f8","a21d0ac1.37a3e8"]]},{"id":"cb8201a0.43b0c","type":"function","z":"649a18f3.49a458","name":"","func":"msg.payload = {data: {Nodes: {\n 1:{ \n Name:\"Test\",\n Properties:{\n 0:{\n 0:\"0\"\n },\n 1:{\n Status:\"Off\"\n }\n }\n \n },\n 2:{ \n Name:\"Test2\",\n Properties:{\n 0:{\n 0:\"0\"\n },\n 1:{\n Not:\"1\"\n }\n }\n \n },\n 3:{ \n Name:\"Test3\",\n Properties:{\n 0:{\n 0:\"0\"\n },\n 1:{\n Status:\"On\"\n }\n }\n \n }\n}\n \n \n \n}\n\n\n\n\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":890,"y":460,"wires":[["2edbe93d.724836","b5700a0b.66f718","a21d0ac1.37a3e8","a2848293.d9125"]]},{"id":"79983133.954c9","type":"inject","z":"649a18f3.49a458","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":710,"y":380,"wires":[["cb8201a0.43b0c"]]}]