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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,552,599
Community Members
 
Community Events
184
Community Groups

Groovy - how to check if an issue is a sub-task

Hi

I am building a custom scripted validator in Groovy and within my script I need to identify whether the current issue is a type of sub-task.  Is there a way I can check this?

1 answer

2 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Feb 14, 2020

Hi @Graeme Johnson 

The sure is a way to check this and it's very easy:

if( issue.issueType.subTask){
//do something for sub-task issue types
} else {
//do something for parent issue types
}

Thanks, that worked a charm.  

What if we want to check if current issue contains a particular Sub-Task named "abc" ?

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 07, 2022

You could try something like this:

def abcSubtaskFound = false
if(issue.subTaskObjects){
abcSubtaskFound = issue.subTaskObjects.any{it.issueType.name == 'abc'}
}

Or as a oneliner:

def abcSubtaskFound = issue.subTaskObjects && issue.subTaskObjects.any{it.issueType.name == 'abc'}

if we want to check - Task issue type have any open subtask(open means issue not in any done status category).

then what should be the script?

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 15, 2023

Something like this should work

 

import com.atlassian.jira.issue.status.category.StatusCategory
issue.subTaskObjects.every{ it.status.statusCategory == StatusCategory.COMPLETE}
we want to do for Task Issue Type while moving to close transition:
Error would be displayed if the task have any open subtasks. (open meaning issue not in any done status category)
Error Message: "All open subtasks needs to be closed"
------------x------------------x-------------x---------------------x---------------------
I have tried this one but, it is also giving an error when all subtasks status are  "Done".
import com.opensymphony.workflow.InvalidInputException;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.status.category.StatusCategory

def issueType = issue.issueType.name == "Task"

if(issueType){

if (issue.subTaskObjects.every{ it.status.statusCategory != StatusCategory.COMPLETE})
 {
    InvalidInputException error = new InvalidInputException()
    error.addError("All open subtasks needs to be closed")
    throw error;

 }
}
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 16, 2023

I think you want either 

if(issue.subTaskObjects.every{ it.status.statusCategory == StatusCategory.COMPLETE}) return null
throw new InvalidInputException('All open subtasks need to be closed')

Or

if(issue.subTaskObjects.any{ it.status.statusCategory != StatusCategory.COMPLETE}){
throw new InvalidInputException('All open subtasks need to be closed')
}

But what you have right now will throw an error only if ALL (every) subtasks are open. If a single one is closed, the validation will pass.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events