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
Try this:
ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find{ it.getValue() == "Priority 1"}.getOptionId()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.