Transition Subtasks along with Parent

Todd Ford June 30, 2017

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 vote
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 3, 2017

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) }
    }
}

 

Todd Ford July 6, 2017

These worked great. Thanks Joshua.

Suggest an answer

Log in or Sign up to answer