Hey everyone,
We're running into a issue we're having trouble figuring out. We're using a cloud instance of JIRA with Scriptrunner, and we're looking to automatically transition an epic to a Done status when all the children of the epic are also marked as Done.
We've found a lot of examples, but with the Cloud instance of JIRA, we can't run the import lines such as:
import com.atlassian.jira.event.issue.DelegatingJiraIssueEvent
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.IssueEventBundle
import com.atlassian.jira.event.type.EventType
in the beginning of our scriptlistener.
This is our script now:
"
// Get the Epic Link value from the Issue
def customField = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == "Epic Link"
} as Map
def epicKey = issue.fields[customField.id]
// Load the epic
def epic = get("/rest/api/2/issue/${epicKey}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body
// Get the current status name of the epic
def statusId = epic.fields["status"].id
// If the epic is in "To Do" status, make sure it gets set to In Progress first
if (statusId == "2") {
post("/rest/api/3/issue/${epicKey}/transitions")
.header('Content-Type', 'application/json')
.body([
"transition": [
"id": "21"
]
])
.asString()
}
// Set the epic to Done (Transition id 11)
post("/rest/api/3/issue/${epicKey}/transitions")
.header('Content-Type', 'application/json')
.body([
"transition": [
"id": "11"
]
])
.asString()
return"
Which works for a single issue moving over the epic to done, but it doesn't take in count of the other children.