Workflow post function validation using Groovy Edited

Hi, everyone!

I'm trying to write a Groovy script in "Transition parent issue" post function in my custom workflow.

My intent is to transition the issue's parent if there is at least one subtask whose status is not "Resolved".

What I tried to do so far was this:

import com.atlassian.jira.issue

for(Issue subTask : parentIssue.get("subTaskObjects")) {
  if(!subtask.getStatus().equals("Resolved"))
    return true
}

return false

The problem is I am new in Jira and know nothing about Groovy!

Obviously it is not working. Can anyone help me??

1 answer

0 vote
Alexey Matveev Community Champion Oct 31, 2017

Hello,

I do not understand exactly what you want.Usually people transition parent issue if all subtasks are resolved. You can use "Transition parent when all subtasks are resolved". It is a built-in post function in ScriptRunner.

If you want to write something opposite then it would be like this:

import com.atlassian.jira.issue

for(Issue subTask : issue.getParentObject().getSubTaskObjects()) {
  if(!subTask.getStatus().Name.equals("Resolved"))
    return true
}

return false

Hello, Alexey! Thanks for your reply!

To be more specific, I have created a status named "Paused" to indicate when some issue still has some task unresolved and none of them is "In progress".

In my "Resolve issue" transition I have two post functions to transition subtask issue parent when its subtask is resolved:

  1. transition subtask parent issue to "Paused", once there is no subtask "In progress" immediately after;
  2. transition subtask parent issue to "Closed". In this case, the parent issue workflow has a condition to just allow that transition if all of its subtasks are closed already.

Because the Groovy validation of the first post function above isn't working, the paused status is always being applied.

That's why I need correct it.

Is it clearer now? If you still have some doubt, please let me know! ;)

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

71 views 0 5
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