Forums

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

Unable to set and update radio button customfield value for a JIRA issue

Komail Badami May 9, 2017

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);

1 answer

0 votes
Craig Nodwell
Community Champion
February 5, 2023
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())

 

Suggest an answer

Log in or Sign up to answer