Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Use customfield value as option id

Name
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 4, 2019

Hello

I use in script

Option targetOption = ComponentAccessor.getOptionsManager().getOptions(customField.getRelevantConfig(issue)).getOptionById(10000L);

to find and set value for MLCS

Is it possible to take this optionByid from customfield in current issue? Like

def s1 = customFieldManager.getCustomFieldObject(11400) 
String s = issue.getCustomFieldValue(s1)


Option targetOption = ComponentAccessor.getOptionsManager().getOptions(customField.getRelevantConfig(issue)).getOptionById("s1"L);

1 answer

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 7, 2019

Depending on the field type for your customfield_11400, you may need to need to go one extra level (if it's a single select).

def s1 = customFieldManager.getCustomFieldObject(11400) 
String s = issue.getCustomFieldValue(s1).value

Then, rather than "s1"L , you should use the toLong() method

Third, long lines of code are harder to read ... I would suggest you break it down a little

And finally, it may be easier on the users or even you to store the value of the option instead of the id in that other custom field.

So this is how I would write this

def s1 = customFieldManager.getCustomFieldObject(11400) 
String s = issue.getCustomFieldValue(s1)

def config = customField.getRelevantConfig(issue)
def options = ComponentAccessor.getOptionsManager().getOptions(config)
Option targetOption = options.getOptionById(s.toLong());
//or
//Option targetOption = options.getOptionForValue(s, null)


Suggest an answer

Log in or Sign up to answer