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")}}
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).
@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.
The proposed suggestions above aren't returning a result though if the summary has any special characters in JMWE.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
YESSSSSSSSSSSSSSSSSSSSS. It worked!!!!! Thank you, i was close but the replaceAll seemed to be the fix ❤
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.