Use customfield value as option id

Name 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
Peter-Dave Sheehan
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 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