Script Runner - Transition JQL Condition

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
Accepted answer

Hi Trevor,

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

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.

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?

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.

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.

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?

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;

Thanks for sharing your solution!

Glad I could help!

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
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,418 views 15 19
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