This is my scenario:
I need to do a JQL and get the number of results (done), if this number is grater than X number do not allow the creation of an issue.
This is my current (example) code:
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter
final String jqlSearch = 'project = "Sample Project"' // the jql query you want to search with
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def searchService = ComponentAccessor.getComponentOfType(SearchService)
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
def total_issues = 0
if (parseResult.isValid()) {
try {
def results = searchService.search(user, parseResult.query, PagerFilter.unlimitedFilter)
def issues = results.issues
//log.warn(results)
issues.each {
//log.warn(it.key)
total_issues++
}
return total_issues
} catch (SearchException e) {
e.printStackTrace()
}
} else {
print("Invalid query")
return null
}
if (total_issues >= 23){
return false
}
Right now is not working, I put this code on the 'Create' transition.