I am creating a JIRA issue programmatically with a listener plugin, it gets its input values from a screen. I have a radio button field whose value I want to be set when the issue creation finishes. The radio button field is present on the given screen when you view/create/edit the issue but the value is not set.
Below is the code
CustomFieldManager custFieldMgr = ComponentAccessor.getCustomFieldManager(); Option optionValue = (Option)issue.getCustomFieldValue(custFieldMgr.getCustomFieldObject("customfield_" + customFieldId)); issue.setCustomFieldValue(customField, optionValue);
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
// the name of the custom field (single select list type)
final customFieldName = 'Single Select List'
// the value of the new option to set
final newValue = 'Option C'
// the issue key to update
final issueKey = 'TEST-1'
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey(issueKey)
assert issue: "Could not find issue with key $issueKey"
def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
assert customField: "Could not find custom field with name $customFieldName"
def availableOptions = ComponentAccessor.optionsManager.getOptions(customField.getRelevantConfig(issue))
def optionToSet = availableOptions.find { it.value == newValue }
assert optionToSet: "Could not find option with value $newValue. Available options are ${availableOptions*.value.join(",")}"
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), optionToSet), new DefaultIssueChangeHolder())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.