I'm trying to write a condition where all subtasks in an issue needs to be in done or canceled state, only then clone the issue. However, the for loop is not checking each element of the collection just the first one. I tried quite a few variations of the for loops yet the result is the same.
The condition should fail if there are any other status for the same issue type.
This is the script:
Collection subTasks = issue.getParentObject().getSubTaskObjects()
for(subTask in subTasks)
{ if (issue.issueType.name == "<issue type name>" && (issue.status?.name == 'Done' || issue.status?.name == 'Canceled')){
return true
} }
Hi Vithya,
I am by no means an expert in either Groovy or ScriptRunner, but from what I can tell, your script gets all sub tasks and checks whether each one of the satisfies your condition, i.e. the if-part. As soon as one sub tasks does, it return true.
Basically it checks if at least one of the sub tasks is of type '<issue type name>' and is either Done or Canceled.
You, however want to make sure that all sub tasks satisfy that condition. You can also formulate that as: If there is at least one sub task that does not satisfy my condition, fail the condition. Now, we can simply reverse your script:
Collection subTasks = issue.getParentObject().getSubTaskObjects()
for(subTask in subTasks) {
if !(issue.issueType.name == "<issue type name>" &&
(issue.status?.name == 'Done' || issue.status?.name == 'Canceled')) {
return false }
}
// After the loop is done, if the script has not yet return false,
// we can return true
return true
Hope that helps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.