ScriptRunner how to automatically transition an Epic to Completion when all its children are complet

Hello Community,

I am trying to develop a ScriptRunner Script that will allow me to transition an Epic to completion once all of the Stories/Tasks/Defects/Subtasks under it are completed.

Could someone point me in the right direction to achieve such functionality.

I appreciate your help!


1 answer

1 accepted

3 votes
Answer accepted

Hi Roberto, 

Hopefully is not too late but I crafted a post function, that should be put into the "Closed" step in the workflow. Hopefully you will understand the logic from the comments added in the code, if not, please shout :)

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.workflow.TransitionOptions

def issue = issue as MutableIssue
def user = ComponentAccessor.userManager.getUserByKey("admin")

parentIssue = issue.isSubTask() ? issue.parentObject :
ComponentAccessor.getIssueLinkManager().getInwardLinks( { == "Epic-Story Link"}?.sourceObject

if (!parentIssue) {
// there is not any Epic issue as source so do nothing

log.debug "Parent issue $parentIssue"

// check if the parent issue has any subtasks that are not closed
def openSubtasks = parentIssue?.subTaskObjects?.findAll { != "Done"}

log.debug "Open subtasks $openSubtasks"
// if there are subtasks that are not open (apart from the one in transition) - then do nothing
if (openSubtasks - issue) {

// get all the open linked (with the epic-story link) issues and are not closed
def linkedIssues = ComponentAccessor.getIssueLinkManager().getOutwardLinks( { == "Epic-Story Link"}*.destinationObject?.findAll { != "Done"}

log.debug "Open linded issues $linkedIssues"
// if there are linked issues that are open (apart from the one in transition) - then do nothing
if (linkedIssues - issue) {

// if the script reached here means that all the subtasks and the linked - with the Epic Story link - issues are closed
// therefore transit the issue
transitIssue(parentIssue, 41, user)

def transitIssue(Issue issue, int actionId, ApplicationUser cwdUser) {
def issueService = ComponentAccessor.getIssueService()

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setComment("This is a comment")

def transitionOptions= new TransitionOptions.Builder()

def transitionValidationResult =
issueService.validateTransition(cwdUser,, actionId, issueInputParameters, transitionOptions)

if (transitionValidationResult.isValid()) {
return issueService.transition(cwdUser, transitionValidationResult).getIssue()

log.error "Transition of issue ${issue.key} failed. " + transitionValidationResult.errorCollection

Please let me know if this does the trick.



Hello Thanos,


thank you for sharing your programming code. I've tried it but it didn't work at our company. I guess maybe it is because of the action id? May I ask how could I find the action id, or why you used 41 in the programming?

Thank you a lot!



Hi Jerry 

In order to find the transition id of the step you have to navigate to the desired workflow and then change the display from diagram to Text and then you will see a column with Transition names and their ids, something like

Screenshot 2019-01-04 at 11.06.05.png

Like 1 person likes this

Hi Thanos,

but unfortunately it still didn't work. I have no idea why not :(




Can you please check your application logs for errors ?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


213 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you