# Getting Label of the Dropdown component

**URL:** <https://forum.inductiveautomation.com/t/getting-label-of-the-dropdown-component/84629>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [January 23, 2024, 12:36pm UTC](https://forum.inductiveautomation.com/t/getting-label-of-the-dropdown-component/84629 "2024-01-23T12:36:31Z")\
**Posts on this page:** 11\
**Page:** 2

<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:** [April 25, 2025, 4:39pm UTC](https://forum.inductiveautomation.com/t/getting-label-of-the-dropdown-component/84629/21 "2025-04-25T16:39:47Z")

</div>

> [@drewdin](#):
>
> Where does index come from?

The OP's dropdown was structured like this:

```python
[
  {
    "value": 0,
    "label": "Option 0"
  },
  {
    "value": 1,
    "label": "Option 1"
  },
  ...
]

```

Selecting the second option from the dropdown would return `value : 1`.  
The OP wanted to return the **label** for that option and thought that the way to that would be to treat the value as an pointer into the options list and then retrieve the label at that position. I provided a much simpler solution.

 ![Dropdown structure index](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/b/5b65460fd76b755f0e10b6b57cb4fc731d8b76d1.png)

To make it work the way the OP was trying:  
Create an expression **structure** 1 and to collect the `index` pointer (the dropdown's `value`) and the dropdown options array.  
Now the structure is passed to the Expression Transform as `{value}` which will look like

```python
{
   "index": 2, "options",
   "options" : [{"value": 0, "label": "Option 0"}, {"value": 1, "label": "Option 1"}, ...]
}

```

Now if `index = 1` the expression I supplied will evaluate as  
`{value}['options'][1]['label']`

As explained, there's a much simpler way.

1 Note that it's an Expression **Structure** and not a simple Expression.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [April 25, 2025, 5:32pm UTC](https://forum.inductiveautomation.com/t/getting-label-of-the-dropdown-component/84629/22 "2025-04-25T17:32:56Z")

</div>

Thanks, I had mine structured the same way, with index and options just like you have shown. It didn't work though, it didn't like index (it liked selectedIndex but it didn't change with my selection).

Instead I Just added a transform and made the value an object with both value/label and it worked. I think that was the recommended way and seemed much easier.

Thanks!

---

<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:** [April 25, 2025, 5:45pm UTC](https://forum.inductiveautomation.com/t/getting-label-of-the-dropdown-component/84629/23 "2025-04-25T17:45:23Z")

</div>

> [@drewdin](#):
>
> Instead I Just added a transform ...

Why though? If you set each option's `value` to the value you'll need after selection it will show up in the `value` property and that can be referenced directly by any script or binding that needs it without a transform.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [April 25, 2025, 6:44pm UTC](https://forum.inductiveautomation.com/t/getting-label-of-the-dropdown-component/84629/24 "2025-04-25T18:44:45Z")

</div>

The value for me is an ID, I need to use to for historian query tags. So for me having the label be the name and the value be an integer was required. But, I wanted the label for exporting the data to excel so I could name the file on what was selected.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [April 25, 2025, 6:46pm UTC](https://forum.inductiveautomation.com/t/getting-label-of-the-dropdown-component/84629/25 "2025-04-25T18:46:25Z")

</div>

I think he meant he used a transform to generate the list of objects, containing both the label and the value.  
Which is the simplest and sanest way to do this, so good for him if I understood correctly.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [April 25, 2025, 6:50pm UTC](https://forum.inductiveautomation.com/t/getting-label-of-the-dropdown-component/84629/26 "2025-04-25T18:50:20Z")

</div>

that is correct, thanks!

---

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [May 2, 2025, 12:59pm UTC](https://forum.inductiveautomation.com/t/getting-label-of-the-dropdown-component/84629/27 "2025-05-02T12:59:56Z")

</div>

> [@Transistor](#):
>
> Create an expression **structure** 1

Very useful way, thanks for the support

---

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [May 5, 2025, 6:27am UTC](https://forum.inductiveautomation.com/t/getting-label-of-the-dropdown-component/84629/28 "2025-05-05T06:27:53Z")

</div>

@Transistor, your expression structure works perfectly when the value in the options is the same of the index, but in the case I'm woking on I have this options for example

```python
[
  {
    "label": "Option 0",
    "value": 110
  },
  {
    "label": "Option 1",
    "value": 13
  }
]

```

How could I manage it using the expression structure?

---

<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 5, 2025, 7:47am UTC](https://forum.inductiveautomation.com/t/getting-label-of-the-dropdown-component/84629/29 "2025-05-05T07:47:40Z")

</div>

You can add extra information into each option dictionary.

```python
[
  {
    "value": 0,
    "label": "Option 0",
    "returnValue": 110
  },
  {
    "value": 1,
    "label": "Option 1",
    "returnValue": 13
  }
]

```

Now the value will contain the array index (which you don't want) so create a custom property `returnValue` on the dropdown, add an expression binding

```python
try(
	{this.props.options}[{this.props.value}]['returnValue'],
	null
)

```

and use `custom.returnValue` where you might have previously used `value`.

The `try(..., null)` just prevents an error when nothing has been selected.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 5, 2025, 7:52am UTC](https://forum.inductiveautomation.com/t/getting-label-of-the-dropdown-component/84629/30 "2025-05-05T07:52:02Z")

</div>

I'd keep the `value` for the actual value and add an `index` property instead.

But what is all this for ? Why not just make `value` an object and add all that's needed here ?

---

<div class="post-metadata">

**Author:** ![cbanzet](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cbanzet/32/6207_2.png) [@cbanzet](https://forum.inductiveautomation.com/u/cbanzet)\
**Post date:** [September 16, 2026, 7:17pm UTC](https://forum.inductiveautomation.com/t/getting-label-of-the-dropdown-component/84629/31 "2026-09-16T19:17:20Z")

</div>

Thank you! I knew Phil's suggestion would be the best, but I couldn't figure out the syntax for "Make the value in the options list an object too". This was the piece I needed. Works beautifully.

[Previous page](https://forum.inductiveautomation.com/t/getting-label-of-the-dropdown-component/84629.md?page=1)
