# Dashboard Dropdown node

**URL:** <https://discourse.nodered.org/t/dashboard-dropdown-node/27412>\
**Category:** Dashboard\
**Created:** [28 May 2020 06:17 UTC](https://discourse.nodered.org/t/dashboard-dropdown-node/27412 "2020-05-28T06:17:46Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [28 May 2020 06:17 UTC](https://discourse.nodered.org/t/dashboard-dropdown-node/27412/1 "2020-05-28T06:17:46Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/a/9ad64cfa689ac4a2fc2774ef59b44b465956d6a8.png)

Drop down result :  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a41fdebb7ab995dd96d98916cecaf78b306de5c7.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 May 2020 06:25 UTC](https://discourse.nodered.org/t/dashboard-dropdown-node/27412/2 "2020-05-28T06:25:57Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [28 May 2020 06:31 UTC](https://discourse.nodered.org/t/dashboard-dropdown-node/27412/3 "2020-05-28T06:31:17Z")

</div>

Dear @Steve-Mcl,

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/2/f21e447ebf67cc76e2aa553c779216ab3feedf75.png)

---

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [28 May 2020 06:38 UTC](https://discourse.nodered.org/t/dashboard-dropdown-node/27412/4 "2020-05-28T06:38:07Z")

</div>

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fce0ed42f824e9405a1bd92b1958a2c7f15995a6.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/4/e4f2349f7e66c845d20311f2e485f375b823f749.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 May 2020 06:38 UTC](https://discourse.nodered.org/t/dashboard-dropdown-node/27412/5 "2020-05-28T06:38:13Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 May 2020 06:39 UTC](https://discourse.nodered.org/t/dashboard-dropdown-node/27412/6 "2020-05-28T06:39:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [28 May 2020 06:47 UTC](https://discourse.nodered.org/t/dashboard-dropdown-node/27412/7 "2020-05-28T06:47:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 May 2020 06:48 UTC](https://discourse.nodered.org/t/dashboard-dropdown-node/27412/8 "2020-05-28T06:48:43Z")

</div>

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

Ps, what would it say in the drop down?

---

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [28 May 2020 07:00 UTC](https://discourse.nodered.org/t/dashboard-dropdown-node/27412/9 "2020-05-28T07:00:46Z")

</div>

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. 😆  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/5047bca4a024bbbf55db75b8e1b2cdb234bca5ff.png)

`[{"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}]`

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 May 2020 07:16 UTC](https://discourse.nodered.org/t/dashboard-dropdown-node/27412/10 "2020-05-28T07:16:06Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b968ad9f95d320f1506e0669c8f7e115f89355c5.png)

The function code...

```auto
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...

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

```

to this msg.options...

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

```

---

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [28 May 2020 07:24 UTC](https://discourse.nodered.org/t/dashboard-dropdown-node/27412/11 "2020-05-28T07:24:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 May 2020 08:34 UTC](https://discourse.nodered.org/t/dashboard-dropdown-node/27412/12 "2020-05-28T08:34:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 June 2020 08:34 UTC](https://discourse.nodered.org/t/dashboard-dropdown-node/27412/13 "2020-06-11T08:34:03Z")

</div>

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