# How to populate dashboard dropdown button dynamically

**URL:** https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594
**Category:** General
**Created:** [8 December 2018 22:19 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594 "2018-12-08T22:19:50Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)
#### Post date: [8 December 2018 22:19 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/1 "2018-12-08T22:19:51Z")

</div>

Hi Guys,

Im trying to populate dynamically the dashboard dropdown button node from previous function-node. I can't find any documentation or examples that can explain how to do it!

Can somebody help me ?

Best Regards,  
Alex

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [8 December 2018 23:04 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/2 "2018-12-08T23:04:29Z")

</div>

> [@aargollo](#):
>
> I can't find any documentation

The sidebar help for the dropdown node tells you how to do it:

> The Options may be configured by inputting `msg.options` containing an array.  
> If just text then the value will be the same as the label, otherwise you can specify both by using an object of `"label":"value"` pairs :
> 
> `["Choice 1", "Choice 2", {"Choice 3":"3"}]`

---

<div class="post-metadata">

### Author: ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)
#### Post date: [8 December 2018 23:54 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/3 "2018-12-08T23:54:06Z")

</div>

Hi Mr. knolleary!  
I would like to populate using a global variable, I started to test with one global variable, as you can see bellow

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9879e29de17edc146726de3eeb2dea81d5b54dab.png)

**My code inside the function (Get\_GlobalValue):**

```auto
var nwkList=global.get('NWKAd');
return {payload:NWKAd};

```

But as you can see on dropdown node above the list value is null.  
Please, would you can advise me how to do it?

Best Regards,  
Alex

---

<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: [9 December 2018 08:30 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/4 "2018-12-09T08:30:50Z")

</div>

> [@aargollo](#):
>
> var nwkList=global.get('NWKAd');  
> return {payload:NWKAd};

That should not run, it should give an error, presumably you mean `return {payload: mwkList}`, however, as previously pointed out it has to be in msg.options, not msg.payload.  
To check the function is doing what you expect feed it into a debug node set to display the full message and check it looks right.

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [9 December 2018 09:39 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/5 "2018-12-09T09:39:22Z")

</div>

Here's a piece of code I use on my Home Automation system.  
It populates a dropdown from a mapping file.

```auto
[{"id":"967d496d.a17698","type":"ui_dropdown","z":"be5ff02b.4c18","name":"Data source","label":"","tooltip":"","place":"","group":"9c66415.50bbe4","order":1,"width":"4","height":"1","passthru":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"datasource","x":710,"y":200,"wires":[[]]},{"id":"ee60cd29.3d4988","type":"function","z":"be5ff02b.4c18","name":"Set-up name-value map","func":"// This mapping file uses {\"name\":\"value\"} pairs to pre-fill the drop-down widget in the dashboard\n\nmsg.payload = \n[\n {\"[Remove all]\":\"delete\"},\n {\"Lounge temperature\":\"lounge/temperature\"},\n {\"Snug temperature\":\"snug/temperature\"}, \n {\"Studio temperature\":\"studio/temperature\"},\n {\"Study temperature\":\"study/temperature\"},\n {\"Rear bedroom temperature\":\"rear_bedroom/temperature\"},\n {\"Rear bedroom humidity\":\"rear_bedroom/humidity\"},\n {\"Rear bedroom pressure\":\"rear_bedroom/pressure\"},\n {\"Garage temperature\":\"garage/temperature\"},\n {\"Loft temperature\":\"loft/temperature\"}\n];\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":200,"wires":[["9cc6ed8a.a5e4e8"]]},{"id":"9cc6ed8a.a5e4e8","type":"change","z":"be5ff02b.4c18","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":200,"wires":[["967d496d.a17698"]]},{"id":"d460741f.cd63c8","type":"inject","z":"be5ff02b.4c18","name":"Trigger","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":200,"wires":[["ee60cd29.3d4988"]]},{"id":"9c66415.50bbe4","type":"ui_group","z":"","name":"Filters","tab":"412738d1.eb7ae","order":2,"disp":true,"width":"24","collapse":false},{"id":"412738d1.eb7ae","type":"ui_tab","z":"","name":"Data capture and charting","icon":"dashboard","order":10}]

```

Hope you find this useful.  
David

---

<div class="post-metadata">

### Author: ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)
#### Post date: [9 December 2018 10:35 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/6 "2018-12-09T10:35:38Z")

</div>

Hi Colin, thanks a lot.  
Do you can explain, please, how can i change it from msg.payload to msg.option in the code?  
I need to keep to use return msg?  
Thanks!  
Alex

---

<div class="post-metadata">

### Author: ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)
#### Post date: [9 December 2018 10:37 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/7 "2018-12-09T10:37:45Z")

</div>

Hi dynamicdave, thanks for share it w/ me!  
Would you can share the nodes that are responsible to persist the menu option in the file. I need to study more to understanding how it works!  
Best Regards,  
Alex

---

<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: [9 December 2018 11:00 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/8 "2018-12-09T11:00:06Z")

</div>

> [@aargollo](#):
>
> Do you can explain, please, how can i change it from msg.payload to msg.option in the code?

```auto
msg.option = global.get('NWKAd');
return msg;

```

In fact I think you can just use a Change node for that instead, but I very rarely use global context, I always pass data with messages, so I would have to look up exactly how to do it.  
Have a look at [Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages) for help on working with messages, also look at the other guides there.

> [@aargollo](#):
>
> I need to keep to use return msg?

Sorry I don't understand the question.

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [9 December 2018 19:41 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/9 "2018-12-09T19:41:02Z")

</div>

Hi Alex,  
Have you tried-out my simple piece of code/flow???  
It includes an array (like Nick suggested) and a "change" node to put things in the correct position.

---

<div class="post-metadata">

### Author: ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)
#### Post date: [9 December 2018 22:20 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/10 "2018-12-09T22:20:45Z")

</div>

Hi Dynamicdave, I tried to use your code, but i cant understanding how can change your code for use global variable. i trying to get a dynamic value received from serial port, using the global set to save, that represent a network address, and transfer it to the menu, using global get (global.get('NWKAd').

@Colin , didn´t have success to use your suggestion, the values still arrive in the drop-down node as "undefined".  
I using a input node to push my function, as i described in my initial post, with payload number equal zero. I tried also set up input node as flow w/ msg.payload or msg.option but also have not worked.

Best Regard,  
Alex

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [9 December 2018 23:37 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/11 "2018-12-09T23:37:53Z")

</div>

Hi @aargollo

The example Colin shared had a mistake in it. He was setting `msg.option` but should have been setting `msg.options` as per the node help.

---

<div class="post-metadata">

### Author: ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)
#### Post date: [10 December 2018 00:01 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/12 "2018-12-10T00:01:53Z")

</div>

I changed it, but i saw in the debug node Err: invalid Options. I using inject node to push my function as you see below:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/546a6a7b9aa13fa27513d504f623a3160d247516.png)

**my function:**

```auto
msg.options = global.get('NWKAd');
return msg;

```

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

I tested the global variable, in the same function node, to be sure that work, and I got success:

The code used to test nwkAdd:

```auto
var nwk_add=global.get('NWKAd') || 0;
msg.payload="NwkAdd "+msg.payload+" "+nwk_add;
return msg;

```

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

Do you have any idea how to fix it?

Best Regards,  
Alex

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [10 December 2018 08:06 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/13 "2018-12-10T08:06:11Z")

</div>

Step1:  
change you debug to show the complete message object.

Step2: Your test shows that your drop down list only contains one value. So what do you expect it to contain? Please debug nodes along your flow to work out where the debug results are different than you suspect. (You can give your debug nodes individual names to make it easier to know which one is which)

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [10 December 2018 09:19 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/14 "2018-12-10T09:19:27Z")

</div>

> [@aargollo](#):
>
> msg.options = global.get('NWKAd'); return msg;

This will work as long as the `NWKAd` value in global context is in the expected formed. Looking at the help text again:

> The Options may be configured by inputting `msg.options` containing **an array**.  
> If just text then the value will be the same as the label, otherwise you can specify both by using an object of `"label":"value"` pairs :
> 
> `["Choice 1", "Choice 2", {"Choice 3":"3"}]`

It expects `msg.options` to be an **array**. Your second Function shows you have a single bare value - `111148`.

So the question, as @ukmoose asks, what do you want the drop down to show and how does that relate to the single value `111148`?

---

<div class="post-metadata">

### Author: ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)
#### Post date: [10 December 2018 09:20 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/15 "2018-12-10T09:20:17Z")

</div>

Hi ukmoose,  
I included the names in the nodes as you advise me.  
In response for your question: I will use a dynamic button to send a command dynamically, w/ nwk address received form another flow stage, I´ll include this information, available in dynamic list, in the new buffer array to send the command. I including bellow a debug information again after change to complete message as you requested me.

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

**Errors:**  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c7260d197605677e14473cf16cef5011d774d101.png)

Best Regards,  
Alex

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [10 December 2018 09:39 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/16 "2018-12-10T09:39:28Z")

</div>

Look at you debug which shows the entire message you are sending to the ActiveList  
Do you see the the dropdown list values within it?

If not you are not setting the GlobalValue correctly.

---

<div class="post-metadata">

### Author: ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)
#### Post date: [15 December 2018 19:18 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/17 "2018-12-15T19:18:51Z")

</div>

Hi ukmoose, sorry for my delay i was traveling this week.

I can´t see in the active list the my global variable, included in the options as "111148".  
I think that my global variable is working, if it doesn't work I would not see the value "111148".

As you see in the screen shot bellow, with a new nwk addr = 228166, the active list show me Invalid Options.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/67c858b968c62b179d9189e97e06f9d34a07666f.png)

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [15 December 2018 19:29 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/18 "2018-12-15T19:29:12Z")

</div>

so let’s go back.

You say you want to create a dynamic list.

To do that you need to send the list items to the node as part of the message object.

Where in the message you just posted is that list?  
What do you expect the values of the dynamic list to be?

---

<div class="post-metadata">

### Author: ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)
#### Post date: [15 December 2018 21:48 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/19 "2018-12-15T21:48:05Z")

</div>

Ukmoose,  
I would like to send the lists of the nwk addresses created as global variable. in the message sent the nwk address is 228166.

I would like to include in the list an array of the nwk addresses.  
I had success to create a list using the method that Mr @dynamicdave said me, that uses an array as you can see below:

```auto
var nwk_add1=global.get('NWKAd') || 0;
msg.payload = 
[ 
    {"Device1": nwk_add1}

];

```

But I would like to compare this method w/ a options method to have sure what is the best way to implement!

Best Regard,  
Alex

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [15 December 2018 21:54 UTC](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594/20 "2018-12-15T21:54:50Z")

</div>

So you need to set msg.options to be an array of the values for that list. Until you do that it will not work.

[Next page](https://discourse.nodered.org/t/how-to-populate-dashboard-dropdown-button-dynamically/5594.md?page=2)
