Jira Cloud - Transition Sub-task when parent is transitioned

Vando Goncalves _e-Core_ December 10, 2019

Hi Guys.

I'm using Jira Cloud and Script Runner, and need to transition all subtasks to a certain status when the parent issues is transitioned.

Which would be the best way to achieve this?

1 answer

1 accepted

1 vote
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 11, 2019

Hi Vando Eduardo de Brito Goncalves,

Thank you for your question.

I can confirm that it is possible to achieve your requirement using ScriptRunner for Jira Cloud and can confirm that to achieve this that you would need to create a Script Listener which is configured on the Issue Updated event.

The script listener would need to check the status of the updated issue and would then need to fetch the subtasks for the issues attached to it in order to check that the status of all subtasks to check if they are all in the required status and if they are to transition the Parent issue

Please note we have some example code located here which shows how to return all of the subtasks for an issue as well as some example code located here which shows how to transition an issue.

I can also confirm that we have an example script located here which shows how to transition an issue when all linked issues are in the closed status and that this script may be a useful reference guide.

You will be able to take these script and use them as a reference guide to help create the script that you require which transitions the story issues when all subtasks are in the done status.

Regards,

Kristian

Vando Goncalves _e-Core_ December 11, 2019

Thanks for your prompt reply @Kristian Walker _Adaptavist_ !

Your informations gave me some guidance on how to start. The only detail I wanted to highlight it's that I want to transition the sub-tasks when the main issue is transitioned.

Once again, thanks a lot !

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 11, 2019

Hi Vando,

Thank you for your response.

I can confirm in this case you can just check if the status of the parent issue changed in the change history and if it did then you can run some code to transition the sub-tasks.

Regards,

Kristian

Vando Goncalves _e-Core_ December 11, 2019

As it might be useful for someone else, here's how I addressed this:

As I needed the sub-tasks to be transitioned when the task was transitioned, I added the below code as a Script Runner arbitrary code post function:

// Specify the transition to execute on the issue
// NOTE - The transition ID must represent a valid transition for the workflow that the issue uses.
def transitionID = '<TransitionIDHere>'


// Note: The search API is limited that to only be able to return a maximum of 50 results
def allSubtasks = get("/rest/api/2/search")
.queryString("jql", "parent=${issue.key}")
.asObject(Map)
.body
.issues as List<Map>


// The rest call to transition the issue


def transitionIssue = allSubtasks.each{
def transitionIssue = post("/rest/api/2/issue/$it.key/transitions")
.header("Content-Type", "application/json")
.body([transition: [id: transitionID]])
.asObject(Map)
}

 

Like # people like this

Suggest an answer

Log in or Sign up to answer