منى
منى

Reputation: 666

JQLParseException: Cannot execute JQL query in ScriptRunner to print number of issues having a specific value for the summary field

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 10.248.75.214 /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.issue.search.SearchProvider
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)

try{
def query = jqlQueryParser.parseQuery(myquery)

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

Upvotes: 1

Views: 666

Answers (2)

منى
منى

Reputation: 666

I found the solution, it should be like this

def query = jqlQueryParser.parseQuery("summary ~ \'" + customDiagnoserId + "\'")

Upvotes: 1

Tom Gionfriddo
Tom Gionfriddo

Reputation: 430

Wrapping your summary string in single quotes ' should fix this.

def myquery = "summary ~ 'aa'"

Upvotes: 1

Related Questions