Change task status in workflow by changing subtask (Workflow Transitions / Groovy)

I am attempting to resolve a very simple issue – I want to have a parent task's status in our workflow change to Resolved, when (and only when) all associated sub-tasks have been moved to Resolved.  To me, this seems like very basic functionality, but I am not a coder.  Our JIRA instance is Cloud / Ondemand, so our plugin options are limited, but I have been working with JIRA Misc Workflow Extensions.

I have looked through the documentation here, and experimented with changing the properties in Workflow Transitions.  Several posts refer to using Conditions or Validators to determine the criteria for a parent task transitioning from one state to another.  I have had some success using Transition Parent Issue in Post Functions – setting a status transition to be "triggered on the issue's parent issue."  

However, I have found that when a task tries to transition a parent task to a state it's already in, I get an error. For example, let's say I create a task with 2 sub-tasks.  I move one sub-task from To Do to In Progress.  The parent task is correspondingly set to In Progress (good so far).  But when I try to move the second task from To Do to In Progress, the parent task is already set to In Progress.  Here is the error message:

image2015-9-4 17:30:35.png

For the life of me, I cannot figure out how to use Workflow Transitions to limit a transition based on criteria (such as excluding an interaction if the parent is already set to a certain status).  I am instead attempting to use a Groovy script – there is an option in Post Functions for a Conditional Execution "only if the Groovy expression returns true."   This simple code has been effective for the above interaction:

 

if(parentIssue.get("status").getName()
== "To Do" || parentIssue.get("status").getName() ==
"Reopened"){

return true;
} else {
return false;
}

 

Again, I am not a developer and have borrowed code from other documentation on this site.  However, I am still unable to address my main problem with subtasks – changing a parent task's status to Resolved if ALL subtasks are marked Resolved (again, using Groovy for a Conditional Execution).  This is the logic I have in mind:

If [there are NO other sub-tasks that are NOT marked Resolved], return True  
Else, return False  

Our workflow is very simple:  To Do / Reopened > In Progress > Resolved > Closed.  Here is the code I have cobbled together:

 

Collection<Issue> subTaskList = subTaskManager.getSubTaskObjects(issue);
 
Resolution resolutionObj=issue.getResolutionObject();
 
 
if(resolutionObj != null && resolutionObj.getName().equals("Resolved")){
boolean anysubtaskNotclosed = false;
 
for(Issue subTaskObj : subTaskList){
 
Status subStatus = subTaskObj.getStatusObject();
 
if(subStatus.getName().equals("Resolved")==false && subStatus.getName().equals("Closed")==false){
 
anysubtaskNotclosed = true;
 
break;
 
}
 
}
 
if(anysubtaskNotclosed = true){
 return false;
} else {
return true;
}
 
}

 

I believe the issue is likely something in the syntax I'm not catching here.  Please advise.

3 answers

Hey Patrick,

Did you find any solution?

I too am trying to run a script in the post function for a conditional execution, the same as you. However, the moment I insert a even a single statement such as

"def isssueManager = ComponentAccessor.getIssueManager();"

the script stops working.

I am not sure, if scripts are meant to be executed within the condition or is it only groovy expressions that can be executed?

Also, what #imports are you using?

Regards,

Nischitha.

Nischitha,

I was able to make some headway after reading the issue Bob Swift posted.  However, JIRA has since been updated to remove the "Conditional Execution" functionality using Groovy, which nullified this solution.  JIRA now displays the following message:

Conditional execution is not available on JIRA Cloud because Groovy scripts are not allowed.

I find it ludicrous that I even needed to consider this lengthy and complicated workaround, for such a fundamental workflow function.  Nevertheless, I recommend you follow and vote for this issue:

https://jira.atlassian.com/browse/JRA-45379

Hopefully an update later down the line will enable this basic customization option.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,723 views 17 21
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