Sort msg.payload Arrays into sections

now what do you want to do after that.

I don't want to do that, @Navybrandon wants that as per his topic ?

yes I did! this helped a lot now to add more arrays!

The goal of having you do this instead of just pasting an output is to help you see how

arrays of objects of objects of arrays inside of objects and arrays are structured.

If you can code it or at least manipulate the code then you can move forward in Javascript

[{"id":"cd174f9.fb8d1b","type":"inject","z":"1fea49bd.2c3b16","name":"","topic":"","payload":"","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1130,"y":940,"wires":[["bf9be9c2.a93358"]]},{"id":"527ed5db.70160c","type":"debug","z":"1fea49bd.2c3b16","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1510,"y":940,"wires":[]},{"id":"bf9be9c2.a93358","type":"function","z":"1fea49bd.2c3b16","name":"FAKE MSG.PAYLOAD","func":"\n\nmsg.payload1 = \n{\n    \"value\":\n    {\n        \"len\":644,\n        \"objectId\":\n        {\n            \"unknown\":'unknown'\n        },\n        \"property\":\n        {\n            \"unknown\":'unknown'\n        },\n        \"values\":\n        [\n            \n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":8,\n                    \"instance\":532897\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001542\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001587\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001589\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001591\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001593\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001594\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001595\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001597\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001598\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001599\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001600\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001601\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001602\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":19,\n                    \"instance\":3002185\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":19,\n                    \"instance\":3002187\n                }\n            },\n        ]\n    }\n}\n    \n\n\n\nreturn msg;\n","outputs":1,"noerr":0,"x":1320,"y":940,"wires":[["527ed5db.70160c"]]}]

Above is the code with 16 arrays. learning something new loving this.

nice! ok so i take it you have some items in that object array that you want to sort for .....
please explain what you want to do now. I'm reading the start of your post again at this moment.

ok so we want it in a dash board like i did in a previous thread.....

do you want all of that data in the array or only spacific data that matches a certain criteria to be listed

do you want it in a drop down, a list, a bunch of buttons ?

@Navybrandon

Its been 30min from your last post.

Did you have a Flash of Genius? and no longer need help?

sorry i was dragged away. on the dashboard it would be amazing for the drop down to have only the last value type and instance number for each array. from pic below i would want to see
array [0] type: 8 instance: 532897
array[1] type:2 instance: 3001587

and so fourth depending on the incoming arrays that vary from pay load to payload.

image

@Navybrandon
Am I correct in assuming that it will always be located at msg.payload1.value.values

@meeki007
yes sir!

am currently writing the start of the code you will need.

I will start it like I had you finish off the objects in the array. Give me 15-20min to get the first chunk done :slight_smile:

Thank you, I appreciate that you help in ways that I still can do stuff. therefore I learn it lol!

based on the link earlier. i have copied the read part in your flow. I figured this would make your life easier.

[{"id":"94db654.6b77498","type":"tab","label":"MEEKI TEST","disabled":false,"info":""},{"id":"3455b5c4.15058a","type":"debug","z":"94db654.6b77498","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1130,"y":260,"wires":[]},{"id":"bdd1934b.f9ee8","type":"function","z":"94db654.6b77498","name":"format array of objects for dropdown in dashboard","func":"//Reformat array to work with dashboard\nvar reformattedArray = msg.payload1.map(obj =>{\n    //declare the reformatted object\n    var rObj = {};\n    //format it for drop down\n    //\"label\":\"value\" is the format so lets move the value to the label and add some txt as well\n    //you can also replce the txt with a var if you want\n    rObj[obj.value+\" text you want to add\"] = obj.channel;\n    return rObj;\n});\nmsg.payload =  reformattedArray;\nreturn msg;\n","outputs":1,"noerr":0,"x":1110,"y":180,"wires":[["eea084ce.5b2cc8"]]},{"id":"eea084ce.5b2cc8","type":"change","z":"94db654.6b77498","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"payload1","tot":"msg"},{"t":"delete","p":"payload1","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":260,"wires":[["94e4698f.95caa8"]]},{"id":"94e4698f.95caa8","type":"ui_dropdown","z":"94db654.6b77498","name":"","label":"","tooltip":"","place":"Select Value From Database","group":"66c4887a.94a298","order":0,"width":0,"height":0,"passthru":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":980,"y":260,"wires":[["3455b5c4.15058a"]]},{"id":"96ecfdd9.b96e3","type":"change","z":"94db654.6b77498","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":180,"wires":[["b042f42d.c5f6b8","3a1a595f.19f016"]]},{"id":"9e76ed39.5e79a","type":"switch","z":"94db654.6b77498","name":"","property":"name","propertyType":"msg","rules":[{"t":"eq","v":"Meeki Test","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":250,"y":180,"wires":[["96ecfdd9.b96e3"]]},{"id":"11e83e33.d26d32","type":"ui_ui_control","z":"94db654.6b77498","name":"","events":"change","x":120,"y":180,"wires":[["9e76ed39.5e79a"]]},{"id":"5269b1bc.9be14","type":"comment","z":"94db654.6b77498","name":"Trigger to populate list when user opens menu tab","info":"","x":290,"y":120,"wires":[]},{"id":"f3b29d3c.4d82d","type":"comment","z":"94db654.6b77498","name":"Dropdown with formatting","info":"","x":910,"y":120,"wires":[]},{"id":"6371eb5f.0daf14","type":"comment","z":"94db654.6b77498","name":"Dropdown without formatting","info":"","x":920,"y":380,"wires":[]},{"id":"5b684f97.fb7ac","type":"change","z":"94db654.6b77498","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"payload1","tot":"msg"},{"t":"delete","p":"payload1","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":500,"wires":[["4b9364e7.ca24fc"]]},{"id":"4b9364e7.ca24fc","type":"ui_dropdown","z":"94db654.6b77498","name":"","label":"","tooltip":"","place":"Select Value From Database","group":"9151ed4a.326c9","order":0,"width":0,"height":0,"passthru":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":940,"y":500,"wires":[["ebd825f6.5a35a8"]]},{"id":"ebd825f6.5a35a8","type":"debug","z":"94db654.6b77498","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1090,"y":500,"wires":[]},{"id":"b042f42d.c5f6b8","type":"function","z":"94db654.6b77498","name":"Read","func":"//var msg = {};\nconst bacnet58 = global.get('bacnet');\n// Initialize BACStack\nvar client = bacnet58({adpuTimeout: 6000});\nvar state = msg.payload1;\nvar I = msg.ip;\nvar B = msg.Bacnet;\n\n \nconst values = [\n {objectId: {type: 8, instance: 532897}, values: [\n {property: {id: 76, index:\"\" }, value: [{type: bacnet58.enum.ApplicationTags.BACNET_APPLICATION_TAG_REAL, value: state}], priority: 15}\n ]}\n];\n\nclient.readProperty( '192.168.1.41' , {type: 8, instance: 532897}, 76, (err, value) => {\n msg.payload1 = {value: value} ;\n node.send(msg);\n});\nreturn msg;","outputs":1,"noerr":0,"x":750,"y":180,"wires":[["bdd1934b.f9ee8","4761b5d4.65929c"]]},{"id":"3a1a595f.19f016","type":"function","z":"94db654.6b77498","name":"Read","func":"//var msg = {};\nconst bacnet58 = global.get('bacnet');\n// Initialize BACStack\nvar client = bacnet58({adpuTimeout: 6000});\nvar state = msg.payload1;\nvar I = msg.ip;\nvar B = msg.Bacnet;\n\n \nconst values = [\n {objectId: {type: 8, instance: 532897}, values: [\n {property: {id: 76, index:\"\" }, value: [{type: bacnet58.enum.ApplicationTags.BACNET_APPLICATION_TAG_REAL, value: state}], priority: 15}\n ]}\n];\n\nclient.readProperty( '192.168.1.41' , {type: 8, instance: 532897}, 76, (err, value) => {\n msg.payload1 = {value: value} ;\n node.send(msg);\n});\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":440,"wires":[["5b684f97.fb7ac","ce3dd9b9.f36788"]]},{"id":"4761b5d4.65929c","type":"debug","z":"94db654.6b77498","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":970,"y":160,"wires":[]},{"id":"ce3dd9b9.f36788","type":"debug","z":"94db654.6b77498","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":850,"y":440,"wires":[]},{"id":"66c4887a.94a298","type":"ui_group","z":"","name":"Formatted","tab":"f9aeb81c.7d9ec8","disp":true,"width":"6","collapse":false},{"id":"9151ed4a.326c9","type":"ui_group","z":"","name":"Un-Formatted","tab":"f9aeb81c.7d9ec8","disp":true,"width":"6","collapse":false},{"id":"f9aeb81c.7d9ec8","type":"ui_tab","z":"","name":"Meeki Test","icon":"dashboard","order":6,"disabled":false,"hidden":false}]

@Navybrandon

I understand you want the user to see array [0] type: 8 instance: 532897 in the drop down list
but when they click it what value do you want to come out in msg.payload ? the instance # of 532897 ?

well that data would move to another flow which then reads that device to get the name. so in this case when they click on that value it sends two msg payloads 1 for type other for instance.

@Navybrandon

I know this is not what you want but wanted to show ya im getting there
Still pecking at it

Screenshot%20from%202019-11-01%2014-23-06

@Navybrandon

You can't send two separate msg when they click the button. However you can send a object

I have the base done

Is this what your looking for?

@Navybrandon

and here it is working in the dashboard

Let me clean up the dashboard and send you a flow

Screenshot%20from%202019-11-01%2014-39-33

the code in the function for thoes reading this entire thread and don't want to import a flow

//input data of msg.payload1.value.values that is an array of object to the var name array_of_objects
var array_of_objects = msg.payload1.value.values;

//map the array to compare each value stored inside each index
 var formated_array_of_objects = array_of_objects.map((current_element_inside_index_number, index_number) =>{
    var reformatted_Obj = {};
    
    // please notice what is happening here. The array.map is mapping one at a time each index_number in the array
    // as each one is pulled it is edited whit the line below. then it returs the new array created
    // its a real small ammount of code but it does allot
    reformatted_Obj['Array [' + index_number + ']' + ' type: ' + current_element_inside_index_number.value.type + ' instance: ' + current_element_inside_index_number.value.instance] = {"type":current_element_inside_index_number.value.type,"instance":current_element_inside_index_number.value.instance};
    return reformatted_Obj;
    
   // payload1.value.values[0].value.instance
   // payload1.value.values[0].value.type
});

msg.payload =  formated_array_of_objects;
return msg;

please import this

[{"id":"a34cc810.384d28","type":"debug","z":"548d67a6.28d68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":650,"y":240,"wires":[]},{"id":"92aa60c.a2ca3a","type":"change","z":"548d67a6.28d68","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":240,"wires":[["a240a9f9.81f17"]]},{"id":"a240a9f9.81f17","type":"ui_dropdown","z":"548d67a6.28d68","name":"","label":"","tooltip":"","place":"Select Value From Database","group":"cec06512.a43738","order":0,"width":0,"height":0,"passthru":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":500,"y":240,"wires":[["a34cc810.384d28"]]},{"id":"532aaeea.6c868","type":"change","z":"548d67a6.28d68","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":180,"wires":[["22b58884.370698"]]},{"id":"1ab11e52.667262","type":"switch","z":"548d67a6.28d68","name":"","property":"name","propertyType":"msg","rules":[{"t":"eq","v":"Meeki Test","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":250,"y":180,"wires":[["532aaeea.6c868"]]},{"id":"6bf567b8.7c91","type":"ui_ui_control","z":"548d67a6.28d68","name":"","events":"change","x":120,"y":180,"wires":[["1ab11e52.667262"]]},{"id":"6badeb6e.36273c","type":"comment","z":"548d67a6.28d68","name":"Trigger to populate list when user opens menu tab","info":"","x":290,"y":120,"wires":[]},{"id":"bdd7eaec.933898","type":"comment","z":"548d67a6.28d68","name":"Dropdown with formatting","info":"","x":670,"y":120,"wires":[]},{"id":"22b58884.370698","type":"function","z":"548d67a6.28d68","name":"FAKE MSG.PAYLOAD","func":"\n\nmsg.payload1 = \n{\n    \"value\":\n    {\n        \"len\":644,\n        \"objectId\":\n        {\n            \"unknown\":'unknown'\n        },\n        \"property\":\n        {\n            \"unknown\":'unknown'\n        },\n        \"values\":\n        [\n            \n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":8,\n                    \"instance\":532897\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001542\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001587\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001589\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001591\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001593\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001594\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001595\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001597\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001598\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001599\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001600\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001601\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001602\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":19,\n                    \"instance\":3002185\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":19,\n                    \"instance\":3002187\n                }\n            },\n            {\n                \"type\":12,\n                \"value\":\n                {\n                    \"type\":2,\n                    \"instance\":3001614\n                }\n            }\n        ]\n    }\n}\n    \n\n\nreturn msg;\n","outputs":1,"noerr":0,"x":700,"y":180,"wires":[["91b86a62.47464"]]},{"id":"91b86a62.47464","type":"function","z":"548d67a6.28d68","name":"solution","func":"//input data of msg.payload1.value.values that is an array of object to the var name array_of_objects\nvar array_of_objects = msg.payload1.value.values;\n\n//map the array to compare each value stored inside each index\n var formated_array_of_objects = array_of_objects.map((current_element_inside_index_number, index_number) =>{\n    var reformatted_Obj = {};\n    reformatted_Obj['Array [' + index_number + ']' + ' type: ' + current_element_inside_index_number.value.type + ' instance: ' + current_element_inside_index_number.value.instance] = {\"type\":current_element_inside_index_number.value.type,\"instance\":current_element_inside_index_number.value.instance};\n    return reformatted_Obj;\n    \n   // array [0] type: 8 instance: 532897\n   // payload1.value.values[0].value.instance\n   // payload1.value.values[0].value.type\n});\n\nmsg.payload =  formated_array_of_objects;\nreturn msg;\n\n\n\n","outputs":1,"noerr":0,"x":160,"y":240,"wires":[["92aa60c.a2ca3a"]]},{"id":"cec06512.a43738","type":"ui_group","z":"","name":"Formatted","tab":"b4be09eb.9c2dc","disp":true,"width":"6","collapse":false},{"id":"b4be09eb.9c2dc","type":"ui_tab","z":"","name":"Meekis solution","icon":"dashboard","order":6,"disabled":false,"hidden":false}]

Now this is going to be one hell of a list to scroll through in a drop down.
I've left out the code where you will separate it into separate lists of 10 in the drop down.

you need to make it only list 10 at a time into separate msg.payloads

Hint >>>
index_number

if index_number is greater than or eq to 10 then ..................

@meeki007
BEAUTIFUL!! it works flawlessly!