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.
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
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.