Issue with binding custom parameters to Perspective Dropdown dataset

In Vision, I am able to create a SQL query that are (n X m) in dimension and then extract the (m) values into parameters to be used in other components. In Perspective I am having trouble doing this?

I have created a view in Perspective. It contains a Dropdown component that is bound to a named queue:
SELECT
OID AS value,
WRK_CNTR_CD AS label,
DSC
FROM SAP_WRK_CNTR WITH(NOLOCK)
WHERE PLNT_CD = :myValueX
ORDER BY WRK_CNTR_CD ASC

Which is returning a dataset of 21x3 and displays it correctly in the dropdown. The selection of the label changes the PROPS.value as expected.

I then added a custom property, on the Dropdown, called test, which has the following property binding and transform

this.props.value

def transform(self, value, quality, timestamp):
“”"
Transform the incoming value and return a result.
Arguments:
self: A reference to the component this binding is configured on.
value: The incoming value from the binding or the previous transform.
quality: The quality code of the incoming value.
timestamp: The timestamp of the incoming value as a java.util.Date
“”"
2 if self.props.value == “”: #account for no selection on dropdown
3 returnValue = “”
4 else:
5 returnValue = self.props.options[value].label
6 return returnValue

I get the following error message in the script:
Error_ScriptEval,”Traceback(most recent call last):
File “” line 5, in transform TypeError:”’com.inductiveautomation.ignition.gateway.datasource.BasicStreamingDataSet’ object is unsubscriptable”)

Have I setup something incorrectly in the Dropdown Dataset that it is not recognizing it as a dataset?

self.props.options is an integer-indexed array, not a key-value data type. When you do self.props.options[value] you’re trying to access a string-keyed value of options when it doesn’t have any. You’ll have to figure out which index in options corresponds to your value parameter.

You can do it like this:

def getIndex(options, value):
	for idx, option in enumerate(options):
		if(option['value'] == value):
			return idx
	return -1

And then you’ll change line 5 to

returnValue = self.props.options[getIndex(self.props.options, value)].label

This code should work, I didn’t test it, but I believe this is what you need to go for.

I have modified the code as follows:

2 def getIndex(options,value):
3 for idx, option in enumerate(options):
4 if(option[‘value’] == value):
5 return idx
6 return -1
7
8 if self.props.value == “”: #account for no selection on dropdown
9 returnValue = “”
10 else:
11 returnValue = self.props.options[getIndex(self.props.options, value)].label
12 return returnValue

I receive the following error in this case:

Error_ScriptEval("Traceback(most recent call last):

File '",line 11, in transform
File"", line 3, in getIndex
TypeError:‘com.inductive.automation.igniiton.gateway.datasource.BasicStreamingDataset’ object is not iterable")

It is acting like it doesn’t understand the dataset is any array of elements? What am I missing?

Oh right. Yes. You have to do some different manipulation on datasets to do things with them like arrays. If you check out the system.dataset documentation there are various ways to work with them.