I try to use Scriptrunner to set Epic Status as part of a issue flow.
The Idea is to attach a script as a post function.
To keep it as simple as possible (to write the script) and as flexible as possible as different projects has different workflows the idea is to have three differnt scrips.
- Setting Epic status to "Done"
- Setting Epic status to "In Progress"
- Setting Epic status to "To Do"
I have done some searches and have found some suggestions I have tried. I have also tried to reverse engineer (See disclaimer) some code to test variants of the code i have found.
As of now I have the following code (some lines added to run it in console):
import com.atlassian.jira.component.ComponentAccessor
// Name of the custom field to change
final customFieldName = "Epic Status"
// New value for that field
final newValue = "Done"
// Console only section
def issueManager = ComponentAccessor.issueManager // console Only
def issueKey = "PLA-136" // console only
def issue = issueManager.getIssueObject(issueKey); // console Only
// end of console only section
def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjects(issue).find { it.name == customFieldName }
//def customField = customFieldManager.getCustomFieldObjectsByName(customFieldName)
log.warn("Value of customField=$customField")
assert customField: "Could not find custom field with name $customFieldName"
issue.setCustomFieldValue(customField, newValue)
The problem is that the code executes without errors, but the issue test on is not updated when I run the script, Epic status still is "To Do".
I see from the documentation that setCustomFieldValue does not actually update the db:
"Sets a custom field value on this Issue Object, but does not write it to the database. This is highly misleading.
To actually set a custom field value, use OrderableField.updateIssue(com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem, MutableIssue, java.util.Map)"
I suspect that this is the problem, but I have no idea on how to use the OrderableField.updateIssue function to achieve this.
Disclaimer:
I have no experience with writing groovy or java in any other that trying to reverse engineer code.
BTW: We use JIRA Server 8.5.6