scriptrunner validation if subtaks all resolved

alex March 24, 2015

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

1 vote
Answer accepted
alex April 1, 2015

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

 

0 votes
alex March 25, 2015

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

 

Simon Kegel //SEIBERT/MEDIA
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, 2015

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

0 votes
Simon Kegel //SEIBERT/MEDIA
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 24, 2015

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. 

Simon Kegel //SEIBERT/MEDIA
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, 2015

@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.

Simon Kegel //SEIBERT/MEDIA
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, 2015

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

alex March 26, 2015

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.

alex March 26, 2015

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

alex March 27, 2015

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.

Suggest an answer

Log in or Sign up to answer