# Script error when Create Dataset to a dropdown list

**URL:** <https://forum.inductiveautomation.com/t/script-error-when-create-dataset-to-a-dropdown-list/81211>\
**Category:** Ignition\
**Created:** [October 30, 2023, 11:57pm UTC](https://forum.inductiveautomation.com/t/script-error-when-create-dataset-to-a-dropdown-list/81211 "2023-10-30T23:57:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ignitionSL](https://avatars.discourse-cdn.com/v4/letter/i/9e8a1a/32.png) [@ignitionSL](https://forum.inductiveautomation.com/u/ignitionSL)\
**Post date:** [October 30, 2023, 11:57pm UTC](https://forum.inductiveautomation.com/t/script-error-when-create-dataset-to-a-dropdown-list/81211/1 "2023-10-30T23:57:22Z")

</div>

I need to rename the items in the dropdown list where the item names are displayed through a query. The dropdown list shows {1,2,3,4}. So, I need to add 'motor' in the front of every number. {motor 1, motor 2, motor 3 ..ect}  
Currently, I am unable to create the dataset in order to send it back to the dropdown list. (I am wiring script transform to query)  
Here is the code

```auto
datas = system.dataset.toPyDataSet(value) # retrieve table data
columnName=list((value.getColumnNames())) #column name 

Tblist = datas.getColumnAsList(0) #column data (rows)
newlist=[]
	for i in range(datas.getRowCount()):
		newlist += ['Inve No _'+ str(Tblist[I])] #add name to front

newdata=system.dataset.toDataSet(columnName,newlist) #create dataset

```

Give this error:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/c/acba1f0c7c47f968bd1dacd965074a10058d2929.png)  
I think, the 'Tblist' is taken as a table with multiple columns but here it should be a single column with multiple rows as this table has only one column.

data:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/a/1ae69e280723754045caffe1d43c29b0eaa8a8f5.png)

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [October 31, 2023, 12:35am UTC](https://forum.inductiveautomation.com/t/script-error-when-create-dataset-to-a-dropdown-list/81211/2 "2023-10-31T00:35:03Z")

</div>

`system.dataset.toDataSet` is looking for a list of lists for the rows parameter. The `+=` appears to be doing an extend operation instead of an append operation.

Also, dropdowns in vision are looking for a two column dataset, one column is `value`, other is `label`. In perspective it looks for a list of dictionaries, with the dictionaries containing the keys `value` and `label`.

You can change `newlist += ['Inve No _'+ str(Tblist[I])]` to be `newlist.append(['Inve No _'+ str(Tblist[I])])`.

Or, you can replace

> [@ignitionSL](#):
>
> ```auto
> Tblist = datas.getColumnAsList(0) #column data (rows)
> newlist=[]
> for i in range(datas.getRowCount()):
> newlist += ['Inve No _'+ str(Tblist[I])] #add name to front
> 
> ```

with

```auto
newlist = [['Inve No _ {0}'.format(datas.getValueAt(x, 0)] for x in xrange(datas.rowCount)]

```

If you are trying to transform a query result into something the dropdown can use, your script should only be

```auto
newDropdownList = [
	{
		'label': 'Inve No _ {0}'.format(value.getValueAt(x, 0)),
		'value': value.getValueAt(x, 0)
	} for x in xrange(value.rowCount)
]

```

---

<div class="post-metadata">

**Author:** ![ignitionSL](https://avatars.discourse-cdn.com/v4/letter/i/9e8a1a/32.png) [@ignitionSL](https://forum.inductiveautomation.com/u/ignitionSL)\
**Post date:** [October 31, 2023, 12:44am UTC](https://forum.inductiveautomation.com/t/script-error-when-create-dataset-to-a-dropdown-list/81211/3 "2023-10-31T00:44:23Z")

</div>

Awesome
