# How to Use DataSet for Dropdown List Component With Scripting

**URL:** <https://forum.inductiveautomation.com/t/how-to-use-dataset-for-dropdown-list-component-with-scripting/56512>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [February 24, 2022, 2:07pm UTC](https://forum.inductiveautomation.com/t/how-to-use-dataset-for-dropdown-list-component-with-scripting/56512 "2022-02-24T14:07:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [February 24, 2022, 2:07pm UTC](https://forum.inductiveautomation.com/t/how-to-use-dataset-for-dropdown-list-component-with-scripting/56512/1 "2022-02-24T14:07:31Z")

</div>

Hey guys,

So in one of my scripts, using Python, I created a variable called engUnits that is a dataset, and it holds the units used (first image).  
 ![engUnits1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/d/7dfb4ed8ef62d3a3e0cd1a88b25301f3bcaa51b4.png)

What I wanted to know or what I was having trouble with was trying to use that data set that I created solely on my script to be used as the options to select in my drop down menu/list component. The second image shows my attempt in trying to insert my dataset I created into my drop down component but I was unsuccessful.

![engUnits2](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/e/3e5ed77635c15553025696d62783b510d3b1d413.png)

Thank you in advance, I greatly appreciate anyone’s help!!

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 24, 2022, 2:20pm UTC](https://forum.inductiveautomation.com/t/how-to-use-dataset-for-dropdown-list-component-with-scripting/56512/2 "2022-02-24T14:20:38Z")

</div>

[https://docs.inductiveautomation.com/display/DOC79/system.dataset.toDataSet](https://docs.inductiveautomation.com/display/DOC79/system.dataset.toDataSet)

If you’re making a dataset from scratch with system.dataset.toDataSet() then it requires two arguments, headers and the data. I am assuming that your engUnits are the headers. So should look more like

`unitDataSet = system.dataset.toDataSet(engUnits, [['row1col1valule', 'row1col2value', 'row1col3value'], ['row2col1valule', 'row2col2value', 'row2col3value']])`

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [February 24, 2022, 2:24pm UTC](https://forum.inductiveautomation.com/t/how-to-use-dataset-for-dropdown-list-component-with-scripting/56512/3 "2022-02-24T14:24:13Z")

</div>

My dataset is a single row, and when I print out my engUnits, it only displays the info inside. How would I find out the name of the Header?

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [February 24, 2022, 2:27pm UTC](https://forum.inductiveautomation.com/t/how-to-use-dataset-for-dropdown-list-component-with-scripting/56512/4 "2022-02-24T14:27:51Z")

</div>

I also wanted to mention that my dataset update or dynamically updates based on what was used. So it can be more than 3 inside the dataset. And as the dataset changes, I wanted the drop down component to update as well.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 24, 2022, 2:31pm UTC](https://forum.inductiveautomation.com/t/how-to-use-dataset-for-dropdown-list-component-with-scripting/56512/5 "2022-02-24T14:31:36Z")

</div>

> [@Jose\_Diaz](#):
>
> using Python, I created a variable called engUnits that is a dataset

Just wanted to point out that this `[u'PSIG',u'',u'F']` isn't a dataset, it is a list.

To create a dataset, you need to make a list of headers **and** a list of data. For it to work with the dropdown, you need have specific headers as expected by the component. If you look at the data property of a fresh dropdown component you can find what is needed.

You will need something like this:

```python
values = [[0,'PSIG'],[1,''],[2,'F']]
headers = ['Value','Label']

engUnitsDS = system.dataset.toDataSet(headers,values)
dropdown.data = engUnits

```

Notice that values is a list of list's. Each item in values must have the same number of items as there are headers.

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [February 24, 2022, 2:59pm UTC](https://forum.inductiveautomation.com/t/how-to-use-dataset-for-dropdown-list-component-with-scripting/56512/6 "2022-02-24T14:59:12Z")

</div>

Would if work if I converted my list as so:

engUnits = [u’PSIG’, u’’, u’F’]

to

engUnits = [[PSIG], , [F] ]

or would I need to add those iteration numbers (0,1,2…)?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 24, 2022, 3:16pm UTC](https://forum.inductiveautomation.com/t/how-to-use-dataset-for-dropdown-list-component-with-scripting/56512/7 "2022-02-24T15:16:45Z")

</div>

The dropdown requires a Value and Label for each item. So you need to provide both, the component expects the value to be an integer.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 24, 2022, 3:37pm UTC](https://forum.inductiveautomation.com/t/how-to-use-dataset-for-dropdown-list-component-with-scripting/56512/8 "2022-02-24T15:37:10Z")

</div>

`engUnitsDS = system.dataset.toDataSet(headers, [list(pair) for pair in enumerate(values)]))`

You could use `enumerate` to automatically…enumerate your original list and add the numbers in sequence.

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [February 24, 2022, 3:46pm UTC](https://forum.inductiveautomation.com/t/how-to-use-dataset-for-dropdown-list-component-with-scripting/56512/9 "2022-02-24T15:46:17Z")

</div>

Just to clarify, my engUnits data is not my headers but the values that I wanted to appear in my dropdown. I think I was able to now create it into a dataset with this.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/c/5c4e31ef1731d32d30debbc11cf444587a920787.png)

The output was: Dataset [3RR ? 2C]

Does this mean I was able to successfully complete it into a data set? Again, thank you all for the help!

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [February 24, 2022, 3:47pm UTC](https://forum.inductiveautomation.com/t/how-to-use-dataset-for-dropdown-list-component-with-scripting/56512/10 "2022-02-24T15:47:11Z")

</div>

![engUnits3](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/3/b36fe39e346d179cdd5a9cf158e6a69f0aefd052.png)  
Here is a better image.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 24, 2022, 3:50pm UTC](https://forum.inductiveautomation.com/t/how-to-use-dataset-for-dropdown-list-component-with-scripting/56512/11 "2022-02-24T15:50:04Z")

</div>

Yes, that means that `engUnitsDS` is a dataset with 3 rows and 2 columns.

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [February 24, 2022, 3:55pm UTC](https://forum.inductiveautomation.com/t/how-to-use-dataset-for-dropdown-list-component-with-scripting/56512/12 "2022-02-24T15:55:38Z")

</div>

Thank you guys!! I was able to successfully update my Drop Down dynamically! Im grateful for the help and this community. I really appreciate it @lrose and @paul-griffith !!!
