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

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


1 badge earned


Participate in fun challenges

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


Gift kudos to your peers

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


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!


Cannot execute JQL query in ScriptRunner to print number of issues having a specific value

I am trying to execute some code in script runner to know how many issues have a certain value as a summary. The code should be super easy and straightforward but I am running into a JQLParseException. I am looking for all issues with value "aa" for the summary field. I am getting this exception in the log file:

2022-08-05 15:18:52,115+0200 https-openssl-nio-443-exec-22 WARN mouh 918x48846x1 19eejnp /secure/CommentAssignIssue.jspa [atlassian-jira.log] myyy exception: com.atlassian.jira.jql.parser.JqlParseException: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException: NoViableAltException(59@[])

I also executed the query in Jira and it returns 274 results so it should work enter image description here Here is my code


  import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Logger
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.opensymphony.workflow.InvalidInputException;
import com.softwareag.jira.insight.helper.Helper;
import java.sql.ResultSet;
import java.util.Map;
import com.atlassian.jira.project.version.Version;
import com.atlassian.jira.workflow.function.issue.AbstractJiraFunctionProvider;
import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.workflow.WorkflowException;
import groovy.sql.GroovyRowResult
import groovy.sql.*
import groovy.sql.Sql
import java.sql.*; 
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.log4j.Logger;
import org.ofbiz.core.entity.ConnectionFactory;
import org.ofbiz.core.entity.GenericEntityException;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

log.warn("HELLO 111")       

def log = Logger.getLogger("atlassian-jira.log")

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
log.warn("MOUNA 3 ")
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
log.warn("MOUNA 4 ")

def issueManager = ComponentAccessor.getIssueManager()
log.warn("MOUNA 5")

// edit this query to suit
// I am looking for all issues with value "aa" for the summary field
def myquery = "summary ~ aa" 
log.warn("total issues  "+ myquery)

def query = jqlQueryParser.parseQuery(myquery)

}catch (Exception e){
    log.warn("myyy exception: "+e)


1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 05, 2022

Hi @Mouna Hammoudi

I have run a basic test in my environment using the code below, and I don't seem to be encountering any issues. It can return all the issues which contain the value Test.

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

def issueManager = ComponentAccessor.issueManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)

def query = jqlQueryParser.parseQuery("text ~ 'Test'")

def search =, query, PagerFilter.getUnlimitedFilter())

log.warn "Total issues: ${}"

search.results.each { documentIssue ->
log.warn "=======>>>> ${documentIssue.key}"

def issue = issueManager.getIssueObject(

log.warn "<<<<====== ${issue.key} ${issue.summary}"

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the test that I ran in my environment:-


 The expected result is returned from the JQL Query if you observe the screenshot above.

I hope this helps to answer your question. :)

Thank you and Kind regards,


Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Aug 06, 2022 • edited

You will see


when the JQL has invalid syntax - although this indeed seems a bit odd why you'd be getting this.

I'd try to escape the search string such as

def myQuery = "summary ~ \"aa\""
def myQuery = "summary ~ 'aa'"

which is also in Ram's test case. Maybe just restricting the search string in quotes will do it - perhaps that Issue Navigator silently does that and sanitizes user input where as the API doesn't?

AUG Leaders

Atlassian Community Events