# Fill drop-down list issue

**URL:** <https://forum.inductiveautomation.com/t/fill-drop-down-list-issue/28933>\
**Category:** Ignition\
**Created:** [October 8, 2019, 8:00pm UTC](https://forum.inductiveautomation.com/t/fill-drop-down-list-issue/28933 "2019-10-08T20:00:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dwoo](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@dwoo](https://forum.inductiveautomation.com/u/dwoo)\
**Post date:** [October 8, 2019, 8:00pm UTC](https://forum.inductiveautomation.com/t/fill-drop-down-list-issue/28933/1 "2019-10-08T20:00:42Z")

</div>

I’m trying to generate a 1-column list and populate a drop-down list when a numeric label changes value.  
The data is read using OPC and any duplicate values are not added to the list.  
When it attempts to convert the List into a dataset I get the error below at the line

dataset = system.dataset.toDataSet(header,oList)

ERROR MESSAGE:  
java.lang.ClassCastException: java.lang.ClassCastException: org.python.core.PyInteger cannot be cast to org.python.core.PySequence

PRINT of the List (oList):  
[0, 13, 14, 8, 122]

CODE:  
if event.propertyName == “value”:

```
	oTags = []
	for i in range(60):
		oTags.append("Tagname_" + str(i) +"_")
	oValues = system.tag.readAll(oTags)

	oList = []

	for x in range(len(oTags)):
		nValue = oValues[x].value
		
		#add new number to droplist 
		if not (nValue in oList):
			oList.append(nValue)

	header = ["Value"]
	dataset = system.dataset.toDataSet(header,oList) 
	sortDataSet = system.dataset.sort(dataset,"Value")
	event.source.parent.getComponent('droplist_1').data = sortDataSet
```

---

<div class="post-metadata">

**Author:** ![nick.schuetz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nick.schuetz/32/6160_2.png) [@nick.schuetz](https://forum.inductiveautomation.com/u/nick.schuetz)\
**Post date:** [October 8, 2019, 8:19pm UTC](https://forum.inductiveautomation.com/t/fill-drop-down-list-issue/28933/2 "2019-10-08T20:19:21Z")

</div>

The oList needs to be a List of rows, not just a list of values.  
Should look more like  
Print of oList = [[0], [13], [14], [8], [122]]

I think the easiest way is to change the line

```auto
oList.append(nValue)

```

to

```auto
oList.append([nValue])

```

---

<div class="post-metadata">

**Author:** ![dwoo](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@dwoo](https://forum.inductiveautomation.com/u/dwoo)\
**Post date:** [October 8, 2019, 8:31pm UTC](https://forum.inductiveautomation.com/t/fill-drop-down-list-issue/28933/3 "2019-10-08T20:31:55Z")

</div>

That worked!  
Now how do you check the List for an existing number? Basically it’s a list of lists now.  
Using

If not (nValue in oList):

doesn’t filter out duplicate values

---

<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:** [October 8, 2019, 8:34pm UTC](https://forum.inductiveautomation.com/t/fill-drop-down-list-issue/28933/4 "2019-10-08T20:34:23Z")

</div>

You could keep it a flat list (so you can easily check membership) and only convert it to a nested list at the last moment before creating the dataset:  
`system.dataset.toDataSet(header, [[i] for i in oList])`

---

<div class="post-metadata">

**Author:** ![dwoo](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@dwoo](https://forum.inductiveautomation.com/u/dwoo)\
**Post date:** [October 8, 2019, 8:39pm UTC](https://forum.inductiveautomation.com/t/fill-drop-down-list-issue/28933/5 "2019-10-08T20:39:12Z")

</div>

BINGO! That worked like a charm 😃

I didn’t know you can convert a list inline…where is that documented?

---

<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:** [October 8, 2019, 8:47pm UTC](https://forum.inductiveautomation.com/t/fill-drop-down-list-issue/28933/6 "2019-10-08T20:47:27Z")

</div>

That’s a generic Python concept known as a “comprehension” - specifically, a [list comprehension](https://www.programiz.com/python-programming/list-comprehension).

---

<div class="post-metadata">

**Author:** ![dwoo](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@dwoo](https://forum.inductiveautomation.com/u/dwoo)\
**Post date:** [October 8, 2019, 8:56pm UTC](https://forum.inductiveautomation.com/t/fill-drop-down-list-issue/28933/7 "2019-10-08T20:56:04Z")

</div>

Thanks! I’m a newbie to Python (I know VB, VBA and VBScript very well though).

---

<div class="post-metadata">

**Author:** ![dwoo](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@dwoo](https://forum.inductiveautomation.com/u/dwoo)\
**Post date:** [October 9, 2019, 7:00pm UTC](https://forum.inductiveautomation.com/t/fill-drop-down-list-issue/28933/8 "2019-10-09T19:00:48Z")

</div>

How would you do the reverse, take a List of Rows and return only a flat List?

I have a returned List from an OPC writeValues call and would like to parse through the list and  
generate a flat list. If a returned value is [GOOD], insert a “1” otherwise a “0” into the flat list.

Here’s the returned List:

[[GOOD], [GOOD], [GOOD], [GOOD], [GOOD], [GOOD], [GOOD], [GOOD], [GOOD], [GOOD], [GOOD]]

flat list would be [1,1,1,1,1,1,1,1,1,1,1]

Or is there a better way just to return a value of “1” if all of the List rows = “GOOD” otherwise a “0”?  
Looking for a elegant solution to determine if there was any error during the OPC writeValues call.

---

<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:** [October 9, 2019, 8:18pm UTC](https://forum.inductiveautomation.com/t/fill-drop-down-list-issue/28933/9 "2019-10-09T20:18:19Z")

</div>

You can use the `all` builtin to check all members of an iterable for a condition. Paired with a comprehension, something like this works:

```auto
l = system.opc.writeValues("Ignition OPC UA Server", ['abc'], [123])

print all(qc.isGood() for qc in l)
>>> False

```

In this case, the QualityCode object returned by `writeValues` has an `isGood` method that conveniently returns a boolean.

---

<div class="post-metadata">

**Author:** ![dwoo](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@dwoo](https://forum.inductiveautomation.com/u/dwoo)\
**Post date:** [October 9, 2019, 8:20pm UTC](https://forum.inductiveautomation.com/t/fill-drop-down-list-issue/28933/10 "2019-10-09T20:20:25Z")

</div>

Perfect! 👏👏
