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

Eitan Gur May 22, 2016

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

4 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 22, 2016

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' }

 

 

Mamie Odette June 14, 2019

Hi,

What if the issue is on creation phase ?

I tried this method in init behaviour, for create issue, it didn't work

Thanks in advance,

Kieu_Le March 4, 2020

I have the same question also.
During issue creation, there is no "issue" object to pass into getRelevantConfig function. How do we get the fieldConfig without "issue" object?

def fieldConfig = cf.getRelevantConfig(??no issue object during create??)

thanks.

Suggest an answer

Log in or Sign up to answer