How to retrieve the option id of the Select List (single choice) custom field

I'm trying to conditionally update by post function a single choice select list.

When doing it by post function copy cf value from field to field - in certain cases it's being updated textually but in a two dimensional gadget for these values I can see that this issue is in "None" value.

Trying to do so by a scripted post function too - but I can't find the option_id's for its optional values.

I can see that this something like "cusomfield_xxxx-val" and then the text of the value.

 

Thanks

1 answer

1 accepted

3 votes
Accepted answer

You need to get and set an option object, not a string or id.

The snippet I used for fetching one should get you going:

def customFieldManager = ComponentManager.getInstance().getCustomFieldManager()

def cf = customFieldManager.getCustomFieldObjectByName("My colour list")

def fieldConfig = cf.getRelevantConfig(issue)

def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'Red' }

 

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Wednesday in Hipchat Cloud

Hipchat Cloud and Stride End of Life: Just over 90 days away

Earlier this year we made the difficult decision to discontinue our team messaging tools, Stride and Hipchat. The end of life date for Stride and Hipchat Cloud is quickly approaching - February 15, 2...

40 views 0 2
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you