Dynamic String fill for the drop-down list

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

Capture2

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

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

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?

Place the following script in the VisionWindowOpened Event.

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.
1 Like

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

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

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

1 Like

If I may:

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.

4 Likes