Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Quotes in JQL query not working in Jira script console

Mouna Hammoudi
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.
November 2, 2022

I am using a JQL query in my code that I am writing in the script console of Jira and I am having some issues with the quotes in the script console as you can see below.
Capture.PNG

Here is the code:

def query3 = ""
try{
query3 = jqlQueryParser.parseQuery("project = \""+myproject.getName()+"\" and created >= -365d and issuetype in (""\"Defect"\"", "Code Roll-in - Maintenance", "Code Roll-in - New Version"))

}catch(Exception e){
log.warn("MounaException "+e)
}

Anyone knows how to fix this problem?

1 answer

1 accepted

5 votes
Answer accepted
Dirk Ronsmans
Community Champion
November 2, 2022

Hey @Mouna Hammoudi ,

Figuring out where and what to escape is always a hassle.

In my experience the easy fix was to mix single and double quotes where you use one for the String definition and the other for the query isolation

Mouna Hammoudi
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.
November 2, 2022

@Dirk Ronsmans

I have combined single and double quotes and it is not working either as you can see below. Could you please write to me your suggestion? Thanks 

Capture.PNG

Dirk Ronsmans
Community Champion
November 2, 2022

I don't have an instance to test on right now but I'd suggest giving this one a try:

 

query3 = jqlQueryParser.parseQuery('project = \"'+myproject.getName()+ \"' and created >= -365d and issuetype in (\"Defect\",\"Code Roll-in - Maintenance\",\"Code Roll-in - New Version\")')

 

You basically use single quotes to open/close the string and double quotes to put around the parameters.

Mouna Hammoudi
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.
November 2, 2022

@Dirk Ronsmans 

I have tried it but it's not working, do you have another suggestion? I am completely lost and you have more experience than me. Here is what I got once I copied and pasted your code: 

Capture.PNG

Dirk Ronsmans
Community Champion
November 2, 2022

Seems I misplaced a quote. Give this one try please.

query3 = jqlQueryParser.parseQuery('project = \"'+myproject.getName()+ '\" and created >= -365d and issuetype in (\"Defect\",\"Code Roll-in - Maintenance\",\"Code Roll-in - New Version\")')

Otherwise could you also tell us what error message you have?

Mouna Hammoudi
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.
November 2, 2022

@Dirk Ronsmans 

It works now. thank you so much! 

Suggest an answer

Log in or Sign up to answer