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

Get count of subtasks with a certain field value

Hello,

We have a script that counts the number of issues returned by a JQL:

....

def getSubtaskIssuesFromJQL(String subtaskjql) {
def adminUser = ComponentAccessor.getUserManager().getUserByKey("admin") 
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()

SearchService.ParseResult parseResult = searchService.parseQuery(adminUser, subtaskjql)
if (parseResult.isValid()) {
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
String subtaskcomment = ""
def commentManager = ComponentAccessor.getCommentManager()
def searchResult = searchService.search(adminUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
subtaskcomment = "This feature request has " + searchResult.total + " subtasks"
return subtaskcomment
}
}

We would like to extend this by counting how many issue resulted from the query have values in a certain select list field.

 

Example: SelectList field has values test, test1, test2, test3

 

The query returns 15 issues. (the select list is mandatory so all of them will have a value)

Output would be: "The feature has 15 issues. 3 test, 3 test1, 5 test2 and 4 test3"

 

Thank you  for any suggestions.

 

 

 

1 answer

1 accepted

1 vote
Answer accepted

didn't really test it, but feel like it should be working:

def getSubtaskIssuesFromJQL(String subtaskjql) {
def adminUser = ComponentAccessor.getUserManager().getUserByKey("admin")
def searchService = ComponentAccessor.getComponent(SearchService)
def customFieldObject = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("your select field name")[0]
def values = ["test", "test1", "test2", "test3"]
SearchService.ParseResult parseResult = searchService.parseQuery(adminUser, subtaskjql)
if (parseResult.isValid()) {
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
String subtaskcomment = ""
def searchResult = searchService.search(adminUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResult.issues
def valuesComment = values.collect { value ->
def issueCount = issues.count {it.getCustomFieldValue(customFieldObject)?.value == value}
"$issueCount $value"
}
subtaskcomment = "This feature request has " + searchResult.total + " subtasks. " + valuesComment.join(",")
return subtaskcomment
}
}

Thank you very much, that works great!

Like Ravi Sagar -Adaptavist- likes this

Suggest an answer

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

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

314 views 1 3
Join discussion

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