Create
cancel
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!

-Roberto

2 answers

1 accepted

4 votes
Answer accepted
Ivan Tovbin Community Leader Feb 21, 2018

Try this:

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

@Ivan Tovbin

This worked perfectly!

Thank you!

-Roberto

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:

getCustomFieldValue(customfieldObject).getClass().name

Get the class and use https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/issue/customfields/option/Option.html to get ID

or

epic.getCustomFieldValue(cfTeam)?.optionId

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
TAGS
Community showcase
Published in Marketplace Apps & Integrations

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

216 views 2 5
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