# Dynamic String fill for the drop-down list

**URL:** <https://forum.inductiveautomation.com/t/dynamic-string-fill-for-the-drop-down-list/27389>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [August 13, 2019, 9:04am UTC](https://forum.inductiveautomation.com/t/dynamic-string-fill-for-the-drop-down-list/27389 "2019-08-13T09:04:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dawei.liu](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@dawei.liu](https://forum.inductiveautomation.com/u/dawei.liu)\
**Post date:** [August 13, 2019, 9:04am UTC](https://forum.inductiveautomation.com/t/dynamic-string-fill-for-the-drop-down-list/27389/1 "2019-08-13T09:04:49Z")

</div>

Hi,

I want to implement a drop-down list with filling its option strings dynamically.  
The strings are stored in a string array of a UDT that from OPC tags

Take below snapshot as example, I want the "String 1" and "String 2" to be displayed in the drop-down list.  
 ![Capture](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/e0c7248a7d0cc899f29640701324de5c159b6b3a.png)

![Capture2](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/7e84abb2cc0ef6f6fdaa5e8781718832c49930d0.png)

I could get the "string 1" & "string 2" from OPC tag with JsonGet function separately by the array index.

I tried to use data set of the drop-down list widgets, it seems that it only support static strings or the dynamical string from SQL database as shown in below link  
[https://docs.inductiveautomation.com/display/DOC80/Vision+-+Dropdown+List+Example](https://docs.inductiveautomation.com/display/DOC80/Vision+-+Dropdown+List+Example)

Is there any way that I could fill these dynamical strings from the OPC UA tag in the property of the dropdown list widget?

![Capture3](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/66a905188e25945aa27f55904b57f3f23c8b914f.png)

---

<div class="post-metadata">

**Author:** ![dawei.liu](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@dawei.liu](https://forum.inductiveautomation.com/u/dawei.liu)\
**Post date:** [August 13, 2019, 2:18pm UTC](https://forum.inductiveautomation.com/t/dynamic-string-fill-for-the-drop-down-list/27389/2 "2019-08-13T14:18:59Z")

</div>

BTW, for the string array that in OPC UDT tag documention type.  
Could the string array content [“sting 1”,“string 2”] in json data {list:[“sting 1”,“string 2”]}  
be considered as dataset directly?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [August 13, 2019, 2:30pm UTC](https://forum.inductiveautomation.com/t/dynamic-string-fill-for-the-drop-down-list/27389/3 "2019-08-13T14:30:07Z")

</div>

Place the following script in the VisionWindowOpened Event.

```auto
options = system.tag.readBlocking(['[providerName]UDTPath/InternalUDTPath'])[0].value # as of v8.0+, tag.read('tagPath') if you're using v7.9.X.
headers = ['value', 'label']
data = []
for i in range(0, len(options)):
	data.append([i, options[i]])
options = system.dataset.toDataSet(headers, data)
system.gui.getParentWindow(event).getComponentForPath('Root Container.Dropdown').data = options

```

To place the script in the required event:

1. Right click the Vision Window node you are using.
2. Select “Scripting”.
3. Expand the “visionWindow” folder.
4. Select “visionWindowOpened” event.

---

<div class="post-metadata">

**Author:** ![dawei.liu](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@dawei.liu](https://forum.inductiveautomation.com/u/dawei.liu)\
**Post date:** [August 13, 2019, 2:33pm UTC](https://forum.inductiveautomation.com/t/dynamic-string-fill-for-the-drop-down-list/27389/4 "2019-08-13T14:33:43Z")

</div>

@cmallonee  
Really appreciate your help. I will try with your comments tomorrow.

---

<div class="post-metadata">

**Author:** ![dawei.liu](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@dawei.liu](https://forum.inductiveautomation.com/u/dawei.liu)\
**Post date:** [August 20, 2019, 11:40am UTC](https://forum.inductiveautomation.com/t/dynamic-string-fill-for-the-drop-down-list/27389/5 "2019-08-20T11:40:23Z")

</div>

Finally, I use another workaround by filling the dataset of drop-down list with items listed in database.

---

<div class="post-metadata">

**Author:** ![Priyanka.Khandge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/priyanka.khandge/32/35989_2.png) [@Priyanka.Khandge](https://forum.inductiveautomation.com/u/Priyanka.Khandge)\
**Post date:** [May 12, 2023, 6:05am UTC](https://forum.inductiveautomation.com/t/dynamic-string-fill-for-the-drop-down-list/27389/6 "2023-05-12T06:05:56Z")

</div>

@cmallonee Thank you so much. This post was helpful to me.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 12, 2023, 8:46am UTC](https://forum.inductiveautomation.com/t/dynamic-string-fill-for-the-drop-down-list/27389/7 "2023-05-12T08:46:34Z")

</div>

> [@cmallonee](#):
>
> ```auto
> data = []
> for i in range(0, len(options)):
> data.append([i, options[i]])
> 
> ```

If I may:

```python
data = list(enumerate(options))

```

`system.dataset.toDataSet` accepts list of tuples, so we might as well use builtins.  
Except if you're not familiar with `enumerate`, in which case use a full loop for explicitness.  
Then learn about `enumerate`, and use it.

Nitpicking, I know. But I'm on a mission.
