Script Runner - Transition JQL Condition

Trevor Hunt
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.
May 18, 2014

Is it possible to pass the current issue into the Script Runner JQL condition?

What I'd like to do is check the status of all subtasks of parent of the current issue and if they're all status X, prevent the transition from being displayed.

2 answers

1 accepted

1 vote
Answer accepted
BenjiI
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.
May 18, 2014

Hi Trevor,

What you want to achieve is best done by workflow conditions in combination with the script runner plugin.

Trevor Hunt
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.
May 18, 2014

That's what I'm trying to do... use the JQL Condition from the script runner plugin. The condition I'm hoping to implment is a check that all other subtasks aren't in status X before displaying a specific transition button.

BenjiI
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.
May 18, 2014

Hi Trevor,

This is how the condition script should look like:

for(subTask in issue.getSubTaskObjects) {
	if(subTask.isSubTask() && subTask.statusObject?.name == 'Your status') {
		return false;
	}
}

return true;

When one subTask has the status, the script returns false and the condition evaluates to false and the transition button will not be visible. When no subtask has the status, the script will return true and the condition evaluates to true and the transition button is visible. As you can see there is no need to use JQL here.

I haven't tested the script, so it could contain some syntax errors :)

Hope this helps?!

P.S: Do you know how to manipulate workflows and add post-functions?

Trevor Hunt
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.
May 18, 2014

I may be mis-reading, but this would be applied to the parent task... what I want to do is have a condition on one of the subtasks based on the status of all of the other subtasks of the same parent...

And yes, I'm very familiar with post-functions and workflows, but I'm more of a hack when it comes to writing the groovy code, I'm afraid. I can read it well enough to modify and extend functionality, but writing from scratch is something I need to work on.

Trevor Hunt
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.
May 18, 2014

Here's essentially what I want to do:

issueFunction in subtasksOf("issueFunction in parentsOf(\"key = $issue\")") and resolution = Unresolved . . .

Where $issue is the current issue being evaluated.

This returns the issues as expected when run via the Issue Navigator and it evaluates just fine when I manually test it via the console, but just not sure what script runner expects to run this with the current issue as the paremeter for the query.

BenjiI
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.
May 18, 2014

Hi Trevor,

This script looks at the parent's other subtasks and evaluates based on some subtask's value:

if(issue.isSubTask()) {
	Issue parent = issue.getParentObject();

	for(subTask in parent.getSubTaskObjects) {
	    if(subTask.isSubTask() && subTask.statusObject?.name == 'Your status') {
	        return false;
	    }
	}
	 
	return true;
}

return false;

When the current issue is no sub-task (no parent available), the condition is false directly.

Is this what you are trying to achieve?

Trevor Hunt
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.
May 18, 2014

Was hoping to use a JQL condition, but this code will accomplish what I'm looking to do:

import com.atlassian.jira.issue.Issue;

if(issue.isSubTask()) {
    Issue parent = issue.getParentObject();
 	
    for(subTask in parent.getSubTaskObjects()) {
        if(subTask.isSubTask() && subTask.statusObject?.name == 'Rejected') {
            return false;
        }
    }
      
    return true;
}
 
return false;

BenjiI
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.
May 18, 2014

Thanks for sharing your solution!

Glad I could help!

2 votes
JamieA
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.
May 19, 2014

I know you have a solution now, but the answer to your question as written is "unfortunately not".

It would be complicated than that because the UI would need to allow "any match", "no matches" etc.

Also as you are looking at "siblings", you would need to have a parentsOf and childrenOf in your jql query, and Benji's method is clearer.

Suggest an answer

Log in or Sign up to answer