Indirect Dropdown Fill

I’m trying to dynamically fill a dropdown list. I have two drop down lists and I want to fill the 2nd list depending on the value of the 1st list. I selected a PropertyChange event handler for the first list so when the value changes, the script will run. I have a table that has dynamic properties (WCn) doing a lookup for data in the table. Here’s my code:dropdown = event.source.parent.getComponent("Dropdown WC") table = event.source.parent.parent.getComponent('Table') if dropdown.Row21 == 0 and table.WC21 == 1: newRow = [21, " Workcenter 21"] dropdown.data = system.dataset.deleteRow(dropdown.data,0) dropdown.data = system.dataset.addRow(dropdown.data, 0, newRow) event.source.parent.getComponent("Dropdown WC").Row21 = 1 if dropdown.Row21 == 1 and table.WC21 == 0: event.source.parent.getComponent("Dropdown WC").Row21 = 1 I tried to use “UpdateRow”, but got a “3rd arg can’t be coerced to org.python.core.PyDictionary” error.

In a perfect world, I’d want an empty dataset containing 25 rows and when the property Table.WCn is “True”, I want to fill in data in row n. I really like the fact that even though the dataset contains 25 rows, the dropdown only displays the rows that contain data. That will work perfectly with what I’m trying to do. Eventually, I’ll want to populate the whole list, but I’m just working with item #21 right now. Is there an easy way to loop this from 0 to 100?

Thanks!

What about doing it with table in your SQL database? I would do the following:

  1. Create a table with 2 columns, list1 and list2.

For example:
list1 list2
fruit apple
fruit banana
fruit pear
tools hammer
tools wrench

  1. Bind list1 to a query that provides the unique values of list1. Such as “SELECT DISTINCT list1 FROM table”. Turn polling off so that the query only runs when the window opens. In this example, you should get 2 options “fruit, tools”

  2. Bind list2 to a query based on list1. Such as “SELECT list2 FROM table WHERE list1 = {list1value}”. Turn polling off. You might see apple, banana, pear.

  3. In script on a value change of list one, refresh the dataset for list2. This will change the values for list2 whenever a new option is selected for list1.

Thanks Nathan. I figured a way that was really clean and simple for this. I made up a handful of tables that I have filled with the data I want to display. Then depending on the 1st drop down, I move the Data Set into the 2nd drop down Data Set via expression. It was seamless and worked w/o any errors or frustrations. I just need to keep those tables not visible and I’m good.

Thanks!

Great!