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

1 votes

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,111 views 13 19
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot