Creation of new sub-task

We have around 8 sub-tasks (A,B,C,D,E,F,G,H) created automatically when a new Jira ticket is created.

There was a requirement came from management where on closing of first 4 sub-task (A,B,C, D) it should create another sub-task (I) and on closing of next 4 sub-task (E,F,G,H) it should create another sub-task (J).

Please let me know how we can achieve this?

Thanks in advance.

Regards
Vinay

1 answer

Here is an idea for postfunction to do this:

import com.atlassian.jira.issue.Issue

/**
 * Creates new subtasks based on statuses of other subtasks
 */

int closed_A = 0;
int closed_b = 0;

for(Issue subtask: issue.getSubTaskObjects()){
    if(true)//check if subtask is one of A, B, C or D
        if(subtask.getStatusObject().getName().equals("Closed"))
            ++closed_A;
    
    if(true) ////check if subtask is one of E, F, G or H
        if(subtask.getStatusObject().getName().equals("Closed"))
            ++closed_b;
}

if(closed_A ==  4){
    //create I
}

if(closed_b == 4){
    //create J
}

Perhaps it will be interesting for you:https://answers.atlassian.com/questions/32982259

Also I would recommend you to use Script PostFunction or CreateSubtask postfunction provided ScriptRunner plugin to run this code.

Hi Vasiliy,

Thanks for the answer. You mean to say I need to add this post function on all the sub-tasks Closed status?

Can you confirm which option to select from Script Postfunction? Because I can see two similar option as per the attached screenshot.

 

Also can you let me know how to create Sub-tasks I and J when the count ==4?

 

Again thanks for your help.

 

Thanks

Vinay

Script Postfunction.JPG

You need Create sub-task option.

Hi vasiliy,

 

Need your further help wrt to configuration.

Please let me know if the configuration as attached in the scrrenshot works. Do I need to add any more configuration.

Script Postfunction.JPG

Thanks

Vinay

Hi vasiliy,

 

Need your further help wrt to configuration.

Please let me know if the configuration as attached in the scrrenshot works. Do I need to add any more configuration.

 

Conf.JPG

 

Thanks

Vinay

Idea is follows: condition is a some boolean expression which returns "true" when you need to create a sub-task.

Here is a code for validator which checks that it requared to create a sub-task I:

import com.atlassian.jira.issue.Issue

/**
 * Creates new subtasks based on statuses of other subtasks
 */

int closed_A = 0;

for(Issue subtask: issue.getSubTaskObjects()){
    if(true)//check if subtask is one of A, B, C or D
        if(subtask.getStatusObject().getName().equals("Closed"))
            ++closed_A;    
}

if(closed_A ==  4){
    return true
} else {
    return false
}

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

240 views 0 11
Read article

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