Script for Dropdown Data

Dear All
Good morning

I am looking for script to update (drop down.data) dynamically.

lets say I have One master template having drop down list associated with one popup window.

Have a number of buttons on main screen and if i press any one of this button it should update the (drop down.data) on opened popup window .

or

I will Manually fill the required string data. If I press the button1 or button2 it will automatically filter the drop down data.

Drop down string name that needs to be update as like below. This device number will be vary based on the PLC.

Button 1:

  1. PLC001Device1
  2. PLC001Device2
  3. PLC001Device3

Button 2:

  1. PLC002Device1
  2. PLC002Device2
  3. PLC002Device3
  4. PLC002Device3

Note : I am using "One column dataset with a set of string values"

Any solution or suggestion in this regard much appreciated

Thank you.

I normally store master lists in a database. Then, a simple query can filter the dataset using the popup or template parameters.

It will be good through script not from data base. Thing is I cannot use database.
Cheers

Then you will have to loop through the master list and manually filter the data.

It will look something like this:

if event.propertyName == 'filterProperty':
	
	# Correct paths as needed
	masterData = event.source.masterData
	filterProperty = event.newValue
	dropdown = event.source.getComponent('dropdown')
	
	filteredHeaders = ['value', 'label']
	filteredData = []
	
	for row in xrange(masterData.rowCount):
		if filterProperty in masterData.getValueAt(row, 'label'):
			filteredData.append([masterData.getValueAt(row, column) for column in xrange(masterData.columnCount)])
		
	dropdown.data = system.dataset.toDataSet(filteredHeaders, filteredData)

Thank you for the script. I am working on that.

In case you don't know, you can run a query in a script with system.db functions.

Don't do it in Vision when called from runscript or other event. Will freeze your UI. Vision should use nothing but named query bindings or asynchronous tasks for queries.