# Drop Down variable selection

**URL:** <https://forum.inductiveautomation.com/t/drop-down-variable-selection/91169>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 30, 2024, 8:18pm UTC](https://forum.inductiveautomation.com/t/drop-down-variable-selection/91169 "2024-05-30T20:18:07Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Craig](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Ryan\_Craig](https://forum.inductiveautomation.com/u/Ryan_Craig)\
**Post date:** [May 30, 2024, 8:18pm UTC](https://forum.inductiveautomation.com/t/drop-down-variable-selection/91169/1 "2024-05-30T20:18:07Z")

</div>

I am creating an HMI that will have 5 different tablets using it, with a drop down of a lot of machine numbers. Is there anyway I can have the drop down of machine number options vary depending on which HMI is being used?

I already have the HMIs set up dynamically so they can all tell which one they are based on their own IP address.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 30, 2024, 8:20pm UTC](https://forum.inductiveautomation.com/t/drop-down-variable-selection/91169/2 "2024-05-30T20:20:57Z")

</div>

Where are you stuck?

---

<div class="post-metadata">

**Author:** ![Ryan\_Craig](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Ryan\_Craig](https://forum.inductiveautomation.com/u/Ryan_Craig)\
**Post date:** [May 31, 2024, 1:07pm UTC](https://forum.inductiveautomation.com/t/drop-down-variable-selection/91169/3 "2024-05-31T13:07:55Z")

</div>

I have a drop down list of 30 or more machines but I need the drop down to only be the 5 machines relevant to the tablet using the program... if that makes sense.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 31, 2024, 1:10pm UTC](https://forum.inductiveautomation.com/t/drop-down-variable-selection/91169/4 "2024-05-31T13:10:13Z")

</div>

But what have you tried?  
Do you have a table with `ipAddress` and `machineId` that you can look up?

---

<div class="post-metadata">

**Author:** ![Ryan\_Craig](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Ryan\_Craig](https://forum.inductiveautomation.com/u/Ryan_Craig)\
**Post date:** [May 31, 2024, 1:13pm UTC](https://forum.inductiveautomation.com/t/drop-down-variable-selection/91169/5 "2024-05-31T13:13:48Z")

</div>

Yes. The tablets currently know which machine they are tied to by looking at their own IP address and comparing that to a SQL table with the IPs and machine numbers on it

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 31, 2024, 1:22pm UTC](https://forum.inductiveautomation.com/t/drop-down-variable-selection/91169/6 "2024-05-31T13:22:29Z")

</div>

It's still not clear where you are stuck.  
You would need a named query along the lines of,

```python
SELECT 
    machineNum AS value,
    machineNum AS label,
    FALSE AS isDisabled
FROM machineAccessList
WHERE ipAddress = :ipAddress
ORDER BY machineNum

```

Set the named query to return the data in JSON format.

On your dropdown, create a query binding on `props.options`, select the named query above and bind the `ipAddress` parameter to wherever you have that stored in the session.

![Machine dripdown](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/3/2306ab9603c9e980b1f862cd6e087e19ab54c252.png)

_The result._

Note that if you add a `description` column to your table you could use a more descriptive name for the dropdown labels.

```python
SELECT 
    machineNum AS value,
    description AS label,
    FALSE AS isDisabled
FROM machineAccessList
WHERE ipAddress = :ipAddress
ORDER BY machineNum

```

---

<div class="post-metadata">

**Author:** ![Ryan\_Craig](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Ryan\_Craig](https://forum.inductiveautomation.com/u/Ryan_Craig)\
**Post date:** [May 31, 2024, 1:52pm UTC](https://forum.inductiveautomation.com/t/drop-down-variable-selection/91169/7 "2024-05-31T13:52:19Z")

</div>

Is there anyway to do this with script? I am trying to avoid creating another "1 off" table if possible. I have been messing around with putting a transform binding on the value and label of the drop down options to look something like this:

```python
def transform(self, value, quality, timestamp):
	if value.machineID == 2:
		 return 'E100'
	elif value.machineID == 3:
		 return 'E200'

```

and so on with a list of all of the machineIDs and E#s but his would create a lot of separate bindings and long scripts on each of them to cover each machine.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 31, 2024, 2:02pm UTC](https://forum.inductiveautomation.com/t/drop-down-variable-selection/91169/8 "2024-05-31T14:02:37Z")

</div>

> [@Ryan\_Craig](#):
>
> to do this with script?

That is a really bad idea. Use a table that ties your tablet IP addresses to the machines.

> [@Ryan\_Craig](#):
>
> avoid creating another "1 off" table

Why? It is the right tool for the task.

---

<div class="post-metadata">

**Author:** ![Ryan\_Craig](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Ryan\_Craig](https://forum.inductiveautomation.com/u/Ryan_Craig)\
**Post date:** [May 31, 2024, 2:21pm UTC](https://forum.inductiveautomation.com/t/drop-down-variable-selection/91169/9 "2024-05-31T14:21:28Z")

</div>

I already have a table that ties the machines to IP address. I just want to tie those machines to a list of presses that are around it, instead of a list of all presses we have.

I don't want to create a table because the presses get moved around and I feel it would be easier to change a script semi-often than to change a table semi-often

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 31, 2024, 2:29pm UTC](https://forum.inductiveautomation.com/t/drop-down-variable-selection/91169/10 "2024-05-31T14:29:01Z")

</div>

> [@Ryan\_Craig](#):
>
> easier to change a script semi-often than to change a table semi-often

Not long term, or for others. Or especially when you are asked to allow management to make the adjustments through a user interface. (You need the designer to change scripts. Any user interface can call database updates.)

Since you already have a table that ties IP to machine, make the new table just tie presses to nearest machine. Then your NQ would join the two tables on machine to get presses for IP address.
