How to limit query output in Groovy Scripted Field and show warning Edited

I am using Scripted field to show the details about the JQL query stored in another field of current issue.

Looks like when user put issuetype = bug instance simply crashed because of 217K bug issue types being loaded to memory.

Now I am trying to put reasonable limit on search request and if it exceeding some number show warning.

I assume that it could be achieved by using new PagerFilter(1) instead of PagerFilter.getUnlimitedFilter() as described in multiple replies on

Now I am trying to understand if I will use new PagerFilter(100) how I can determine if there are more than 100 results to show warning that JQL is possibly wrong?

Something like:

def pf = new PagerFilter(100)

def query = jqlQueryParser.parseQuery(cfJQLQueryVal)
def results =, user, pf)

if ( pf.getPages().size() > 1 ) {

error ..

} else {

results.getIssues().each {rissues ->




I am going to test this but any help will be nice ...

1 answer

You should be able to get the number of pages from results.pages.

if (results.pages.size() > 1) {
    //....add your error here

Keep in mind the other caveats about JQL in scripted fields:

Another thought is that you might be able to automatically restrict the JQL a bit more (e.g. limit it to the issue's project, to open issues, or some other important context) by adding some clauses to the user input JQL. You may also want to run the query through the SearchService's validateQuery method:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

// get all the used invoice numbers so far
def query = ComponentAccessor.getComponent(JqlQueryParser).parseQuery(queryText)
def pagerFilter = new PagerFilter(100)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def searchService = ComponentAccessor.getComponent(SearchService)
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def messages = searchService.validateQuery(loggedInUser, query)
if (!messages.hasAnyErrors()) {
    def results =, loggedInUser, pagerFilter)
// of your code here }

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,701 views 3 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you