Auto-close issues,when parent issue is closed

Hello,

I wonder how can I close subtasks, when parent issue is closed. I have found something like post-functions example codes (here).

I'm using the same code from the example above for default workflow (just testing ;) ) and instead of closed sub-tasks I've got sth like this:

groovy.lang.MissingPropertyException: No such property: a for class: Script2

I must admit that I am not best in 'grooving'- could anyone help me? I would really appreciate.

We are on JIRA 6.0.4 with Script Runner 2.1.17
Best wishes,
JW

7 answers

1 accepted

0 votes
Tarun Sapra Community Champion Mar 26, 2014

Hi Jan,

Your code seems to be fine, only thing that might be going wrong is the transition Id

workflowTransitionUtil.setAction (5)

Make sure you use the transition Id from your workflow instead of the one given in the docs

can you share your code ??

You can do it quite easily with JJupin and a short SIL Script Post Function:

string sk;
if (%key%.status == "Closed") {
  for (sk in subtasks(key)) {
    %sk%.status = "Closed";
  }
}

Best Regards,

Silviu

Here you are:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import org.apache.log4j.Category
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
 
log = Category.getInstance("com.onresolve.jira.groovy.AutoCloseChildIssues")
 
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
 
SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager();
Collection subTasks = issue.getSubTaskObjects()
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
    subTasks.each {
        log.debug ("issue.statusObject.name: " + issue.statusObject.name)
        workflowTransitionUtil.setIssue(it);
        workflowTransitionUtil.setUsername(currentUser);
        workflowTransitionUtil.setAction (5)    // 5 == RESOLVE ISSUE; 10023 - zakonczony
 
// Add a comment so people have a clue why the child has been closed
//  CommentManager commentManager = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class);
//    String comment = "*Resolving* as a result of the *Resolve* action being applied to the parent.";
//   commentManager.create(it, currentUser, comment, true);
 
        // validate and transition issue
        workflowTransitionUtil.validate();
        workflowTransitionUtil.progress();
    }
}

"workflowTransitionUtil.setAction (5)" <-- Here is the scrap I should change If I'd like to use another action, right? ( id == 10023 for my workflow)

Tarun Sapra Community Champion Mar 26, 2014

see my answer below..

Hi,

You can do it quite easily with JJupin and a short SIL Script post function:

string sk;

if (%key%.status == "Closed") {

  for (sk in subtasks(key)) {

    autotransition("Close Issue", sk);

  }

}

Hey,

Thanks a lot for your answer.

Silviu,

unfortunately JJupin isn't for free and this may be a little problem to use it.

Tarun,

What is the best way to check my transition ID? In my database, I can see that (like in the code above): 5 == RESOLVE ISSUE; 10023 == Zakonczony

"Zakonczony" with Id == 10023 is my target action.

Tarun Sapra Community Champion Mar 26, 2014

In the code above- 5 is the transiton ID which will take the issue to current status to resolve status thus you need to know your transition ID of the transtion that you wish to execute which can be global transition( from all statues to closed) or it can be a single transtion( form a particular status to closed)

Just open your project workflow through the admin rights to access the workflow section of the jira instance

yourjiraInstance/admin/workflows/ListWorkflows.jspa

Now in the workflow you can clearly se the transition id next to transition name.

example

StartProgress(4)

Move to done(20)

Move to close (40)

what you see in the paranthesis is the transition id.

Now it works :) Thank you very much!

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,760 views 11 18
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
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