Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Sub-task transition when Parent task changes state

Rahul Savaikar
Contributor
July 19, 2019

I have a requirement in JIRA Service Desk, where multiple Sub-tasks need to be created. Once the Parent request is approved and automatically goes to the "In Progress" state, all the Sub-tasks need to go to the "In Progress" state.

 

For instance, a Service Request is created where

- "Services", a multi select list field contains values - JIRA, Confluence

- "Product category", a cascading select contains value - Standard Laptop >> Linux

here, 2 Sub-tasks for "Services" and "Product category" are successfully being created.

 

Question:

Now, when the Service Request is approved, it moves to the "In Progress" state. What I want is that, all the Sub-tasks too should move to "In Progress" state once the Service Request is approved and moves to the "In Progress" state. Is this possible at all?

 

My hosted JIRA version is 17.3.3, and I am using Scriptrunner version 5.5.6.

 

Can anybody please help me out?

 

Let me know if any further details are required.

2 answers

1 accepted

2 votes
Answer accepted
Matias Stachowski
Contributor
July 22, 2019

Here's a snippet that does what you asked

 

1. Make a scriptrunner event which reacts to Generic Events.

2. Put in the code and change the variables

 

It checks if the latest change is a status change from "To Do" to "In Progress", and if it is, it changes all subtasks which are in "To Do" through a transition in the workflow

 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.IssueInputParametersImpl

//Name of the status FROM and TO
def TODONAME = "To Do"
def INPROGRESSNAME = "In Progress"
//ID of the transition the subtask should use to go to start (see workflows)
def TRANSITIONID = 11
//Type of issue it should exclusively work for
def ISSUETYPE = "Task"

if (event.issue.getIssueType().getName() != ISSUETYPE)
return;

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def issueService = ComponentAccessor.getIssueService()
def issue = event.issue
def changes = changeHistoryManager.getChangeHistories(issue)
def user = changes.get(changes.size() - 1).getAuthorObject()

//Get latest change and check all the change item beans
for (ChangeItemBean changeItemBean : changes.get(changes.size() - 1).getChangeItemBeans()) {
//Check if latest history change contains a status change from TO DO to IN PROGRESS
if (changeItemBean.getField() == "status" &&
changeItemBean.getFromString() == TODONAME &&
changeItemBean.getToString() == INPROGRESSNAME) {

//Update all subtasks via the TRANSITIONID transition
for (Issue subtask : issue.getSubTaskObjects()) {
if (subtask.getStatus().getSimpleStatus().getName() != TODONAME)
continue;
log.warn("Transitioning issue $subtask.key through action $TRANSITIONID")
def transitionValidationResult = issueService.validateTransition(user, subtask.getId(), TRANSITIONID, new IssueInputParametersImpl())
if (transitionValidationResult.isValid()) {
def transitionResult = issueService.transition(user, transitionValidationResult)
log.warn(transitionResult.isValid() ? "Transition Succes" : "Transition Not Valid")
} else {
log.warn("The transitionValidation is not valid")
}
}
}
}

Rahul Savaikar
Contributor
July 23, 2019

WOW! This worked like a charm 
Thank you very much @Matias Stachowski.

0 votes
Durga prasad panda
Contributor
July 23, 2019

WOW! This worked perfectly fine @Matias Stachowski
Thank you very much.

Suggest an answer

Log in or Sign up to answer