Dashboard Dropdown node

Greetings,

Tried to do a drop down for node red dashboard to display for the date selection from a database. Pushed the date array to the msg.options. But the result shows undefined.

Any suggestion will be appreciated, thank you in advance.

Best Regards.

Date array :
image

Drop down result :
image

Have you checked with a debug node (set to show complete message) what is going into the drop-down node? The debug output you posted shows the values in payload not options

1 Like

Dear @Steve-Mcl,

After checking, found there's empty in msg.options.
Here is the complete message result :

Sorry, I just get the result. But the selection shows "datelog" not the date :joy_cat:

image

Hi. When you post code, it is preferable that you post text instead of a picture as it's easier to edit.

I can see the problem. The items in your array rows are objects not at arrays so you can't simply access [0]

That's what they're called haha. So either modify your database select or modify the property name in your function.

1 Like

Hmmm...Do you mind to give some example on how to change the property name? :rofl:

Sure. Post you function and I'll show you where.

Ps, what would it say in the drop down?

I'm trying to make the data into a inject node. But the actual one is object in array, not array in array. But I think it's not problem for you to do it. :laughing:
image

[{"id":"7a0d4fb1.e84e6","type":"function","z":"ecd7ee06.58772","name":"","func":"msg.topic = \"SELECT distinct datelog FROM training_room;\";\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":120,"wires":[["9618923b.dec4e"]]},{"id":"52ad4473.3f2fec","type":"inject","z":"ecd7ee06.58772","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"3","x":130,"y":120,"wires":[["7a0d4fb1.e84e6"]]},{"id":"9618923b.dec4e","type":"Stackhero-MySQL","z":"ecd7ee06.58772","server":"e71c7b1f.eb9258","name":"","x":430,"y":120,"wires":[["4c6196e7.862398"]]},{"id":"4c6196e7.862398","type":"function","z":"ecd7ee06.58772","name":"","func":"var arr=[];\nvar myarr=msg.payload;\nfor (i = 0; i < myarr.length; i++)\n{\n arr.push(myarr[i]);\n}\nmsg.options = arr;\nmsg.payload = arr;\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":120,"wires":[["13bdbda0.44edf2"]]},{"id":"2535d94c.419e56","type":"inject","z":"ecd7ee06.58772","name":"Fake DB Result","topic":"","payload":"[[\"datelog : 27-5-2020\"],[\"datelog : 28-5-2020\"]]","payloadType":"json","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":280,"y":200,"wires":[["bc7ac064.5a97d"]]},{"id":"13bdbda0.44edf2","type":"ui_dropdown","z":"ecd7ee06.58772","name":"","label":"","tooltip":"","place":"Select option","group":"95c24894.4a4c48","order":1,"width":0,"height":0,"passthru":true,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":760,"y":120,"wires":[["6d126b0f.aae754"]]},{"id":"6d126b0f.aae754","type":"ui_toast","z":"ecd7ee06.58772","position":"bottom right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":false,"topic":"","name":"","x":970,"y":120,"wires":[]},{"id":"bc7ac064.5a97d","type":"debug","z":"ecd7ee06.58772","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":470,"y":200,"wires":[]},{"id":"e71c7b1f.eb9258","type":"Stackhero-MySQL-Server","z":"","name":"","host":"localhost","port":"3306","tls":false,"database":"thdb"},{"id":"95c24894.4a4c48","type":"ui_group","z":"","name":"DATE SELECTION","tab":"42fca57e.91fedc","order":1,"disp":true,"width":"6","collapse":false},{"id":"42fca57e.91fedc","type":"ui_tab","z":"","name":"History Data","icon":"history","order":3,"disabled":false,"hidden":false}]

Hi, i only wanted your function but thanks for trying to fake the data - that is normally a big help.

Firstly, I assume this is the output you want?...
image

The function code...

var arr=[];
var myarr=msg.payload;
for (i = 0; i < myarr.length; i++)
{
    let entry = {}; //create empty object
    entry[myarr[i].datelog] = myarr[i].datelog;//using bracket notation, add a new propery which is the date from DB and set it to the same value
    arr.push(entry);
}
msg.options = arr;
return msg;

Lastly, this is likely something more suited to 1 change node + JSONata - but I dont know how.

If anyone wants to follow up, he needs to change

this msg.payload...

[{"datelog":"27-5-2020"},{"datelog":"28-5-2020"}]

to this msg.options...

[{"27-5-2020":"27-5-2020"},{"28-5-2020":"28-5-2020"}]
1 Like

Thank you @Steve-Mcl for taking the time and effort, the selection shows the date now after I modified the function code. :heart_eyes:

If you read the node red docs page on Working With Messages and the one Writing Functions they will give you lots of useful information which will help you solve these problems in the future.

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