Need help escaping characters in JMWE

Brent Malnack February 20, 2023

I've got a rather complex post function that creates a bunch of tasks and subtasks when an Epic is created. In creating multiple issues, I have avoided having commas in the summaries of the issues for obvious reasons; being the delimiter, it creates another issue.

To avoid that, I've adjusted the summary text. In some places, I have replaced the comma with a forward slash. This looks to be a reserved character in JMWE.

Here is an example:

The task summary created by the Epic:

Notification of Equipment Purchase / altering or relocation

Checking for a match in the task workflow:

if issue.fields.summary.match(r/^Notification of Equipment Purchase // altering or relocation/i)

(I have to use the match method as the Summary is concatenated with the Epic Name)

 

I've tried both single quotes and double. If I don't use two forward slashes I can't even test it. So it doesn't find a match. I have similar issues with texts that include "and or" in them.

 

Any suggestions?

2 answers

1 accepted

0 votes
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 20, 2023

Hi @Brent Malnack 

I'm not sure where exactly you're trying to escape characters. But generally, to avoid issues with commas and other special characters, the easiest is to use the "Iterator returns JSON" option of the Create Issue(s) post function. This way, you can use just about any character in string values.

Also, you mentioned "Checking for a match in the task workflow". Do you mean in a Build-your-own Condition or Validator? Or a Conditional Execution of a post function? Can you please elaborate?

Brent Malnack February 20, 2023

Sorry. Posted my response accidently as an answer above.

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 20, 2023

I'm not sure where you're using this Nunjucks template, but in any case, your problem is that you have a forward slash in a regular expression. The solution is to "escape" the forward slash using a backslash:

{% if issue.fields.summary.match(r/^'Notification of Equipment Purchase \/ altering or relocation'/i) and issue.fields.components | find({"name":"Transfer"}) != null %}

Also, I'm not sure why you added single quotes around the regular expression. Is the summary you're looking for something like:

'Notification of Equipment Purchase / altering or relocation'

with the quotes?

Also, why use the match method with a regular expression instead of just == ?

Like Brent Malnack likes this
Brent Malnack February 20, 2023

That solved it! On the regular expression, each item in the iterator gets named with the Epic so by the time I'm evaluating it, the name is the task summary name + the Epic summary name. Since that changes each time they create an Epic, I needed to be able to dynamically match it.

0 votes
Brent Malnack February 20, 2023

Appreciate the feedback. Not sure that selecting JSON is going to help. I get this error when trying to test the template for this line in the template window:

{% if issue.fields.summary.match(r/^'Notification of Equipment Purchase / altering or relocation'/i) and issue.fields.components | find({"name":"Transfer"}) != null %}

 

There was an error during the rendering of your template

Message:
(string) [Line 1, Column 74]
  parseSignature: expected comma after expression

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