JIRA - How to set custom field value in script runner using groovy script?

1 minute read

Jira allows you to create a custom field and the value can be set during the transition, so when you view or edit the issue, then the custom value will be displayed on the custom field after the configured transition is executed.

Ex: The custom field value needs to be set after the issue is moved from open to inprogress in the workflow, then the below script can be written in the transition.

Code:

import com.atlassian.jira.component.ComponentAccessor;

// Set the custom field name in the variable
String customFieldName = "Custom status";

// Get the custom field manager
def customFieldManager = ComponentAccessor.customFieldManager;
// Get the custom field objects and find the custom field by it's name
def customStatusCustomField = customFieldManager.getCustomFieldObjects(issue).find {it.name == customFieldName};
// Set the value to the custom field
issue.setCustomFieldValue(customStatusCustomField, "test")

Leave a comment