Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner condition for sibling status

Hi, I'm looking to create a condition on a transition that is dependent on whether or not siblings of a certain issue type are in a particular status. 

I've found a solution from 2016 but code has since been deprecated.

def parent = issue.parentObject
def otherSubtasks = parent.subTaskObjects.findAll { in ["A", "B"]}
return otherSubtasks.every { == "Resolved"

 Now we are supposed to use getIssueType() and getStatus(). 

Two questions:

  1. How do I use getIssueType with the "otherSubtasks" array?
  2. I'm not sure what the code looks like for the getStatus replacement.

I know this is wrong but wanted to show I tried:

import com.atlassian.jira.issue.Issue

def parent = issue.parentObject
def otherSubtasks = parent.subTaskObjects.findAll { == "Estimate"}
return otherSubtasks.every {
otherSubtasks.getStatus() = "Final"

1 answer

1 accepted

0 votes
Answer accepted

Hi Amy,

You've almost nailed it. Here's the correct way:

import com.atlassian.jira.issue.Issue

Issue parent = issue.getParentObject()
List<Issue> otherSubtasks = parent.getSubTaskObjects().findAll{it.getIssueType().getName().equals("Estimate")}

return otherSubtasks.every{it.getStatus().getName().equals("Final")}

Hi Ivan, thanks for your help! I've tried this but getting an error:

[Static type checking] - Cannot assign value of type java.util.Collection <com.atlassian.jira.issue.Issue> to variable of type java.util.List <Issue>

You can pretty much ignore this error. It'll work just fine as is. Thing is static type checking in Scriptrunner is not always accurate. 

However if you wanna get rid of this error simply change "List" to "Collection" in the code.

Ok, thanks for that. I'm getting this error and I think it's because the siblings are not subtasks? I mistakenly assumed that any child was a subtask but these siblings are tasks which is why this if failing:

Cannot invoke method getSubTaskObjects() on null object

 I definitely have siblings of that issue type within the same Epic so I'm not sure why it would be null unless it has to do with them not being subtasks.


This error occurs because the issue this script is executed in is NOT a subtask and as such does not have a "parent". That's why the parent here is null, hence the error.

Now that we have this out of the way, I think I can still help you with this, but first could you clarify what exactly do you mean by "siblings"?

Sure. I have the following hierarchy:


  -Estimate issue type (task)

  -Intake issue type (task)

  -Job issue type (task)

My objective is to prevent the Job task from being put into IN PROGRESS state if the Estimate and Intake are not in the DONE state. So I've set this condition on the Job issue type, though it might be better practice to put is as a validator.

Condition is the correct approach here. Make sure you put it on your transition that leads to "In Progress" status.

The code is as follows:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue

import org.slf4j.Logger
import org.slf4j.LoggerFactory

Logger log = LoggerFactory.getLogger("LOG")

CustomFieldManager cfMgr = ComponentAccessor.getCustomFieldManager()
def epicLinkMgr = getBean("epicLinkManagerImpl")
Issue epic = issue.getCustomFieldValue(cfMgr.getCustomFieldObjectByName("Epic Link")) as Issue
log.error("Epic issue: ${epic.getKey()}")
List<String> issueTypeList = Arrays.asList("Estimate", "Intake")
List<Issue> issuesInEpic = epicLinkMgr.getIssuesInEpic(epic).findAll{issueTypeList.contains(it.getIssueType().getName())}
log.error("Issues to check: ${issuesInEpic.toString()}")
log.error("Issue statuses: ${issuesInEpic.collect{it.getStatus().getName()}.toString()}")

return issuesInEpic.every{it.getStatus().getName().equals("Done")}

def getBean(String beanId){
def ghPlugin = ComponentAccessor.getPluginAccessor().getEnabledPlugin("com.pyxis.greenhopper.jira")
def descriptor = ghPlugin.getModuleDescriptor("greenhopper-launcher")
def applicationContext = descriptor.getModule().greenHopperCacheManager.applicationContext
def beanInstance = applicationContext.getBean(beanId)
return beanInstance;

Unfortunately, still allowing me to transition to In Progress despite both Estimate and Intake not sitting in Done. Is there any way to find out what's allowing that?

Just to clarify, your Intake and Estimate issues are connected to an epic via "epic link" field and not a simple issue link, right?

Yes, here's a screen grab showing that we have both the Estimate and the Intake tasks within "Issues in Epic" as well as the new task that I'm trying to prevent the "OK to Begin" transition:

I put the script on a Condition on the "OK to Begin" transition within the Task workflow as shown here:

However, it's still showing as an option when the other two are not Done: 

That's odd. I've added some logging to the code above to be able to see what exactly is going on there. Could you please update your code with it and send me a screenshot of your script logs.? To quickly get to them, open your conditions tab and click on the last green ckeckmark (or red X) in your scripted condition. Make sure the code is executed after the update before your check the logs.

Ok, here's the log:

The following log information was produced by this execution. Use statements"...") to record logging information.

2018-10-02 14:52:40,266 ERROR [LOG]: Epic issue: AMGNLUS-58
2018-10-02 14:52:40,294 ERROR [LOG]: Issues to check: [AMGNLUS-59, AMGNLUS-60]
2018-10-02 14:52:40,295 ERROR [LOG]: Issue statuses: [IN PROGRESS, TO DO]

Ok, so we know that we are getting the correct issues and we are getting their statuses right. The problem seems to be in 'return' statement. Try chaning it to:

return issuesInEpic.every{it.getStatus().getName().equalsIgnoreCase("Done")}

Thanks for your help, Ivan. But unfortunately, it's still allowing me to push this task. Can you clarify what part of this script disables the transition?

The script should return logical true for the transition to become available or logical false otherwise. The 'return' statement does that in this case.

'every' closure returns true if the condition inside the closure is true for every element of the 'issuesInEpic' list. 

Interesting: I just tried running it as a validator and it seems to work as intended. 

Marked this as answered but want to clarify that this worked as a Validator rather than a Condition for me.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

481 views 16 17
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you