Trouble finding index of a dropdown selection

Hi all - I need to get the index of a dropdown selection, and based on existing forum searches have tried the following two approaches, but neither are working - would LOVE any advice, thank you!

The list of options is Current User's custom_status_labels_1
And the dropdown selection is Dropdown Custom1's value

Approach 1: Toolbox JS tools
Using Toolbox, just add an Expression element to do the search, as follows:
image

Unfortunately, this returns a blank. Note the element is visible on page load

Approach 2: 1T - Index Finder plugin
I also tried using the 1T-Index Finder plugin, but when I add a FindIndex element, there are no options:
image

Thanks a ton for any advice!

Arbitrary text:

Dropdown’s choices (the search expression used to fill the drop-down options):each item’s unique ID

This produces a comma separated list of the unique IDs of the drop-down list.

Then, to the arbitrary text:

extract with Regex:

,(?=.*?unique ID of the selected value)

And after the extract with Regex:

:count + 1

Essentially, this counts the number of commas before the relevant unique ID in the arbitrary text, which gives you the index of the unique ID.

Your final expression will look like:

Arbitrary text:extract with regex:count + 1

Edit: if you’re using an option set, you can just use the Display of the option set instead of the unique ID (but be sure to remove any commas/conflicting characters in the Display)

1 Like

Thanks @georgecollier !
For some reason, there is no ‘unique id’ option on either the list or the dropdown value:

image

There is also no “Display” option that I can see.

The list is indeed a list of texts, and the value is a text. I’ve verified both here:

Any idea why that might be?

EDIT: note that these options are not their own data types - they are Fields in the User data type

Oh, it’s just a list of texts? Okay, then do the same method but instead of unique IDs in the arbitrary text just put each item (e.g Current User’s custom status labels). A list of texts by default will be formatted as a CSV list.

Same goes for the regex expression, replace the unique ID with the Dropdown’s value.

1 Like

That worked! Posting screenshots for future users:



image

1 Like

@georgecollier actually there’s an issue with this approach: if nothing is selected in the dropdown, it returns the max index (instead of -1):
image

Thoughts on how to address that?

There’s probably a more intelligent solution bit use Dropdown is empty:format as text

When yes: -1
When no: (your current expression)

1 Like

Thanks @georgecollier ! I’m not as familiar with JS, so I’m struggling to figure out the syntax properly, could you give me a sense of what that would look like? Thank you so much!

image

Ah I actually found an easier way to implement the conditional, from the docs at Run Javascript - Toolbox docs

You just add a conditional to the Expression field:
image

Why are you using an expression element at all? Just store the index number in a group of type number.

This topic was automatically closed after 70 days. New replies are no longer allowed.