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.
Hi Nick,
Thank you for your question.
I can confirm that we have created an example of a script located here which can be ran on the script console inside of ScripRunner for Jira cloud to show how you can transition issues returned by a JQL query.
You will be able to use this script as a reference in order to create a script which returns all the children for the Epic in a JQL query and then transitions these issues to the required status.
Please not that when executing a transition a script will only be able to transition the issue, if the transition to the required status from the current status exists inside of the workflow.
If this issue has solved your requirement can you please mark it as accepted so that other users can see it is correct when searching for similar answers.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.