scriptrunner validation if subtaks all resolved

I have scriptrunner in Jira 6.2 and a Workflow with several steps and subtasks. In each phase of the workflow, I need a validation if the previous subtasks (2-5 per phase) are closed or resolved before moving on to the next step. The Next step button should always be visible, but an exception shall be thrown and the transition stopped.

I tried using the example condition “All sub-tasks must be resolved” in simple scripted validator, but i guess this wont work out. I cannot use this script on validation page, or?

Thanks for any hints.

3 answers

1 accepted

now i finally found a way to check and validate against open subtasks:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Category
import com.atlassian.jira.config.SubTaskManager

Collection subTasks = issue.getSubTasks()

if (issue.getSubTasks().status.contains ("1")){
            return false     	
}
else return true

the status "open" alway has the value 1

 

Hey Alex, 

if it doesn't work probably your workflow doesn't resolve issues and just set them in the next status (closed, done etc).  
when this is the case set a condition in your sub-workflow that the issue must have a resolution to bet closed and set a screen with resolution in this transition as well.
Hope this is your problem- because it's easy to fix. laugh 

Have a nice day and provide feedback if this was your problem. 

@Alex Alex I think you missunderstood the function. Yes you can set it as a validator / condition - BUT it doesn't check if your issues are closed. Maybe closed isn't the last status in your workflow so it's not that good hint. It just check if tickets are resolved - not the status. Resolved means that the issue got a resolution (field). This can be fixed, won't fix, done, can't reproduce etc. And this is what the condition checks - resolution is Not empty.

sorry for the wrong mention - didn't get the other Alex :(

Hi Simon, thank you for detailed explanation. i now understand the function underneath. I will have a deeper look into that, until i find a solution for my notification-validation problem.

Hi Simon, thank you for your quick answer! i'm not quite sure if i understand you correctly. there is an exapmle in script-runner plugin when creating a condition: all subtasks must be closed.

that is exactly what i need, but also with a workflow-warning poping up. And this warning, i assume, is only possible in validators-section when configure a transition.

therefor i'd like to create my own script in add parameters to validator -> simple scripted validator -> condition:

import com.atlassian.jira.issue.Issue
import org.apache.log4j.Category
import com.opensymphony.workflow.InvalidInputException

SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager();
Collection subTasks = issue.getSubTasks()
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
    subTasks.each {
        if (!(it.resolution > 0))
            passesCondition = false
    }
}

So when one of my subtasks is at status open, throw exception - else proceed.

sorry if this is completly wrong thinking - i'm newby to Jira-world

ok now i set my subtask workflow to automatically set the resolution to completed when closing. so for my validation, the code above should return a false statement and the exception sall be thrown if one or more resolutions aren't set. but somehow it always return true. i cannot access log or have any option for debugging.

so, nobody used some kind of notifications? is there any other possibility to warn a user if subtasks aren't closed before proceeding?

 

Can't mention you - cause to your username :( Wrote an explanation above

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
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

222 views 1 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