Handling Special Characters in JMWE Query for Jira Text Fields
Overview
This documentation provides guidance on handling special characters in Jira text fields, including the Summary field, when using the JMWE (Jira Misc Workflow Extensions) searchIssues
function. Special characters such as -
, _
, and |
can affect the accuracy of search queries. The following instructions and examples will help ensure that JMWE queries work correctly even with these special characters.
Problem Statement
When querying Jira tickets using JMWE, special characters in text fields like the Summary field can cause syntax issues or unexpected behavior. This issue is particularly relevant when using the ~
operator in JMWE queries.
Instructions
Understanding the Issue: Special characters in text fields can disrupt JMWE query syntax. For example, double quotes or backslashes can prematurely close string literals or cause parsing errors.
Correct Syntax for JMWE Query: To handle special characters in text fields effectively, follow the corrected syntax provided below:
Corrected Syntax:
{{('project = XYZ and issuetype = "XYZ" and summary ~ "\\"' + issue.fields.summary.replaceAll('"',' ').replaceAll('\\',' ') + '\\"" order by created DESC') | searchIssues(maxResults = 1, fields = "key") | field("key")}}
Explanation:
Escaping Characters: Use double backslashes (
\\
) to escape special characters like double quotes and backslashes in the query string.Replacing Double Quotes: The
replaceAll('"', ' ')
function replaces double quotes in the Summary with a space to prevent syntax issues.Handling Backslashes: Similarly,
replaceAll('\\', ' ')
replaces backslashes to avoid conflicts in the query.
Implementation Steps:
Identify Special Characters: Determine which special characters are present in the Summary field that might affect the query.
Apply Escaping and Replacement: Use the provided syntax to escape or replace special characters in the Summary field.
Test Queries: Verify the functionality by running test queries to ensure that the search results are accurate and that special characters are handled correctly.
Additional Considerations:
Jira Query Limitations: The
~
operator in JQL is a loose match operator. It will return issues whose summaries contain the words in the current issue’s summary. The=
operator is not supported for text fields like Summary in Jira.Error Handling: Ensure that any syntax errors or unexpected results are addressed by reviewing the query and making necessary adjustments.
By following these guidelines, you can ensure that JMWE queries handle special characters in Jira text fields correctly, leading to more accurate and reliable search results.