Forums

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

JMWE - searchIssues function with tickets that have special characters in summary

Ahmad Sidawi
Contributor
August 25, 2023

Hi,

 

We have many tickets which contain characters like '-', '_', '|'. In JQL we can apply something like this to run a query without issue:

https://confluence.atlassian.com/jirasoftwareserver/search-syntax-for-text-fields-939938747.html

 

I'm trying to run something similar in JMWE but unable to get the right syntax, any help would be appreciated :) 

 

What i've tried (which works fine for items without special characters in the summary):

{{('project = XYZ and issuetype = "XYZ" and summary ~ ' + '"/"' + issue.fields.summary + '/""' + ' order by created DESC') | searchIssues(maxResults = 1, fields = "key") | field("key")}}

1 answer

1 accepted

2 votes
Answer accepted
David Fischer
Community Champion
August 25, 2023

Hi @Ahmad Sidawi 

I'm not sure what you're trying to achieve here, but the way to escape a character in Nunjucks is to precede it with a backslash (eg. "a \" quote"). But since you're using single quotes around the string, you don't even need to escape double-quotes (just like you didn't around XYZ):

{{('project = XYZ and issuetype = "XYZ" and summary ~ "' + issue.fields.summary + '" order by created DESC') | searchIssues(maxResults = 1, fields = "key") | field("key")}}

However, this is dangerous, as the summary might contain invalid characters, the worst being the double-quote since it would prematurely close the string literal. You can use this to avoid that issue:

{{('project = XYZ and issuetype = "XYZ" and summary ~ "' + issue.fields.summary.replaceAll('"',' ') + '" order by created DESC') | searchIssues(maxResults = 1, fields = "key") | field("key")}}

In any case, this kind of JQL search won't always return the expected issues, because the ~ JQL operator is a loose match operator so, for example, it will match issues whose summary contains the words in the summary of the current issue. Unfortunately, Jira doesn't support using the = operator on the Summary field (or any text field).

Ahmad Sidawi
Contributor
August 25, 2023

@David Fischer so in the above link the search syntax for special characters has the backslashes and it works well in JQL (the addition of "/" and /""),  which i'm trying to replicate in JMWE.

Screenshot 2023-08-25 185704.png

The proposed suggestions above aren't returning a result though if the summary has any special characters in JMWE.

 

Screenshot 2023-08-25 185438.png

David Fischer
Community Champion
August 25, 2023

Oh, I see. I didn't know about the JQL syntax using double-quotes inside the search string.

In that case, this should work:

{{('project = XYZ and issuetype = "XYZ" and summary ~ "\\"' + issue.fields.summary.replaceAll('"',' ').replaceAll('\\',' ') + '\\"" order by created DESC') | searchIssues(maxResults = 1, fields = "key") | field("key")}}

However, it will still look for issues whose Summary contains the current issue's Summary. For example, if the current issue's Summary is:

The quick brown fox 

it will also return an issue whose Summary is

 The quick brown fox jumps over the lazy dog

 and that's a limitation of Jira.

Ahmad Sidawi
Contributor
August 25, 2023

YESSSSSSSSSSSSSSSSSSSSS. It worked!!!!! Thank you, i was close but the replaceAll  seemed to be the fix ❤

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events