Transition Subtasks along with Parent

We're using JIRA Software 7.3.1. We have Adaptavist ScriptRunner (5.0.4). I've seen questions posted that sound earily similar to this, but haven't been able to get far with them. (I did cause our server to hang after one attempt though.) I'm a total scripting newbie and a JIRA near-newbie. I'm afraid I need a For Dummies version of this.

The two things that've been asked of me are:

When an issue is transitioned to "Done," transition all of its Subtasks to "Done."

When an issue is transitioned to "In Progress," transition the subtasks with the same Assignee as the parent issue to "In Progress."

1 answer

Hi Todd, 

You can accomplish this by using post-functions in ScriptRunner. For your first problem of transitioning an issue's subtasks to "Done" whenever the issue is transitioned to done, you'll need to add a script post-function on the transition step to Done. The following script will transition all of the subtasks. You'll need to replace the number for workflowActionId to the ID of your transition, which you can easily find on the text view of your workflow in JIRA.

 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

def Issue issue = issue

def workflowActionId = 2 //replace with your workflow step ID
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def adminUser = ComponentAccessor.userUtil.getUser(currentUser.name)
def IssueService issueService = ComponentAccessor.issueService

issue.subTaskObjects.each {
    def TransitionValidationResult validationResult = issueService.validateTransition(adminUser, it.id, workflowActionId, issueService.newIssueInputParameters())
    if (validationResult.valid) {
        issueService.transition(adminUser, validationResult)
    }
}

For the second problem, you'll repeat the same steps as the first problem by adding another script post-function to the In Progress transition. However, you'll just need to modify the script to check to see if subtask assignee matches parent assignee (it.assignee == issue.assignee).

 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

def Issue issue = issue

def workflowActionId = 2 //replace with your workflow step ID
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def adminUser = ComponentAccessor.userUtil.getUser(currentUser.name)
def IssueService issueService = ComponentAccessor.issueService

issue.subTaskObjects.each {
    if (it.assignee == issue.assignee) {
    def TransitionValidationResult validationResult = issueService.validateTransition(adminUser, it.id, workflowActionId, issueService.newIssueInputParameters())
    if (validationResult.valid) {
        issueService.transition(adminUser, validationResult) }
    }
}

 

These worked great. Thanks Joshua.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Thursday in Jira

Updates to jira.atlassian.com give you visibility into what's coming in Jira Server and Data Center

Hello, Community! My name is Gosia and I'm a Product Manager on Jira Server and Data Center here at Atlassian. Since 2002 when we launched our public issue tracker, jira.atlass...

480 views 1 14
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