# Dropdown setting options for another dropdown

**URL:** <https://forum.inductiveautomation.com/t/dropdown-setting-options-for-another-dropdown/56230>\
**Category:** Ignition\
**Created:** [February 16, 2022, 7:49pm UTC](https://forum.inductiveautomation.com/t/dropdown-setting-options-for-another-dropdown/56230 "2022-02-16T19:49:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [February 16, 2022, 7:49pm UTC](https://forum.inductiveautomation.com/t/dropdown-setting-options-for-another-dropdown/56230/1 "2022-02-16T19:49:21Z")

</div>

one dropdown sets the machine

one dropdown sets the products

I don’t want to have a possible product on a machine it can’t run

So I am already thinking binding the property to get a look at which machine is selected

I then don’t know how to return the option set though

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [February 16, 2022, 8:02pm UTC](https://forum.inductiveautomation.com/t/dropdown-setting-options-for-another-dropdown/56230/2 "2022-02-16T20:02:03Z")

</div>

I am reading

> [@Dynamic drop down lists](https://forum.inductiveautomation.com/t/dynamic-drop-down-lists/18708):
>
> I would like to use the selections from one drop down to control and alter what can be selected on another drop down. Is this possible in ignition and if so any assistance on the script would be appreciated.

I think it covers it, not sure yet.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [February 16, 2022, 8:12pm UTC](https://forum.inductiveautomation.com/t/dropdown-setting-options-for-another-dropdown/56230/3 "2022-02-16T20:12:03Z")

</div>

that seems like it was maybe much older

I think I can go to value, bind that to the property

add a transform script with a list for each option, plug in the value, spit-out the value I want?

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [February 16, 2022, 8:27pm UTC](https://forum.inductiveautomation.com/t/dropdown-setting-options-for-another-dropdown/56230/4 "2022-02-16T20:27:43Z")

</div>

It is alive

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/9/89a5ee40a6dbff3dcb4d0f1e1c584b6361903d69.png)

maybe the database way is better in some ways?

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [February 16, 2022, 8:42pm UTC](https://forum.inductiveautomation.com/t/dropdown-setting-options-for-another-dropdown/56230/5 "2022-02-16T20:42:33Z")

</div>

I have used the database approach. For my purposes its Buildings/Tenants vs Machine/Parts, but the method is the same. The first dropdown has a list of locations, the second one has a query binding that retrieves the list of tenants for the selected building using a parameter containing the selected building.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 16, 2022, 8:58pm UTC](https://forum.inductiveautomation.com/t/dropdown-setting-options-for-another-dropdown/56230/6 "2022-02-16T20:58:23Z")

</div>

The database approach is going to be far more resilient in the long run. Supposing you have a DB where you have three tables `MACHINES`, `PRODUCTS`, and `MP_CORR`, then I recommend something like this:

Bind the options for Dropdown\_0 to a Named Query, which has something like this (I also recommend using the JSON option instead of “auto”):

```auto
select id, name from MACHINES

```

and use a transform:

```auto
return [{"label": machine.name, "value": machine.id} for machine in value]

```

Then bind the options of Dropdown\_1 with the same general approach.  
Named Query ( **parameterized** ):

```auto
select id, name from product where id in (select product_id from MP_CORR where machine_id=:machineId)

```

This might seem like a lot of overhead, but imagine trying to lock down all of the places in your project which might need to be updated as you add/remove machines/products/locations. You should never hard-code that sort of product information into a project.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [February 16, 2022, 9:47pm UTC](https://forum.inductiveautomation.com/t/dropdown-setting-options-for-another-dropdown/56230/7 "2022-02-16T21:47:34Z")

</div>

I will attempt this tomorrow.

What is MP\_Corr?  
How does the `for machine in value` part work in the return?

I will make one relatively static table for this instead of the lists then.  
Thanks for the help

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 16, 2022, 9:57pm UTC](https://forum.inductiveautomation.com/t/dropdown-setting-options-for-another-dropdown/56230/8 "2022-02-16T21:57:39Z")

</div>

`MP_CORR` is an assumed table which correlates machine/product relationships

```auto
MACHINES
id | name
0 | Machine0
1 | Machine1

PRODUCTS
id | name
0 | Product0
1 | Product1

MP_CORR
machine_id | product_id
0 | 0
0 | 1
1 | 1

```

Would then represent a system where there exists two machines and two products, and Machine0 uses both Product0 and Product1, whereas Machine1 only uses Product1. Without some sort of table which stores the relationship between machines and products you won't be able to set this up.

> [@zacharyw.larson](#):
>
> How does the `for machine in value` part work in the return?

That's a bit of [list comprehension](https://www.w3schools.com/python/python_lists_comprehension.asp) from python. Essentially the transform will iterate over every item in the query (which has been passed into the transform as `value`), and alias the "item" as "machine", before converting the "machine" item into a dictionary which has two keys ("label" and "value") and assigning `machine.name` and `machine.id` as the values of those keys.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [February 18, 2022, 6:19pm UTC](https://forum.inductiveautomation.com/t/dropdown-setting-options-for-another-dropdown/56230/9 "2022-02-18T18:19:50Z")

</div>

It looks like next week I will get to it  
Thanks for explaining
