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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

292 views 5 0
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