Auto-close issues,when parent issue is closed

hagen March 26, 2014

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
Answer accepted
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 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

0 votes
hagen March 26, 2014

Now it works :) Thank you very much!

0 votes
hagen March 26, 2014

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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 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.

0 votes
Silviu Burcea
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.
March 26, 2014

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

  }

}

0 votes
hagen March 26, 2014

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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 26, 2014

see my answer below..

0 votes
Silviu Burcea
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.
March 26, 2014

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

0 votes
RambanamP
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.
March 26, 2014

can you share your code ??

Suggest an answer

Log in or Sign up to answer