Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner - How to grab the ID of an option

Hello Community,

I am trying to figure out how to grab the ID of an option from a select list.

I am able to grab the textual value from the field but now I want to map out what is the ID for that specific textual value.

Below is my current code that allows me to grab the textual value:

// Get the issue
/*MutableIssue currentIssue = getIssueContext() as MutableIssue

//Get the custcom Field
def custom_field = customFieldManager.getCustomFieldObjectByName("Country Priority");

// Get the Config for the field
def fieldConfig = custom_field.getRelevantConfig(currentIssue)

// Find the option to set, grab the value in country priority
def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == "Priority 1"}

In the above code I grab the customfield, grab the options and filter out on the specific one I want. This for somereason returns me "Priority 1". What I need it to return is the ID/Value of Priorty 1, which happens to be 11322.

Does anyone know who I can fetch that value?

Thank you!


2 answers

1 accepted

4 votes
Answer accepted

Try this:

ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find{ it.getValue() == "Priority 1"}.getOptionId()

@Ivan Tovbin

This worked perfectly!

Thank you!


How to get OptionId for child in cascading dropdown

2 votes
Danyal Iqbal Community Leader Feb 21, 2018

If you want to get the optionID of the option that is already set in the CustomField you can use:


Get the class and use to get ID



If you want to set the customfield, use

def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == "Priority 1"}

issue.setCustomFieldValue(cf, value)

Why do you need the ID?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

Marketplace Partner Spotlight: Fine Software

Happy New Year, everybody! What better way to kick off 2022 than with a new Marketplace Partner Spotlight ✨ This month, we're getting to know Daniel Franz, co-founder of Fine Software. Fine Software ...

429 views 2 15
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you