This is Jira Data Center 8.20. In an automation rule and Edit Issue action I am attempting to extract a section of the Description to set as the value of a multi-line text field. E.g. The Description may look like this.
Name: My Name
Title: My Title
Strengths/Weaknesses: Good coder, good unit tester
knowledge of multiple languages
weak at debugging code written by other developers
Preferred Location: The Beach
Documentation Status: Pending
What I want to extract is everything following "Strengths/Weaknesses: " up to "Preferred Location" and store this in a multi-line text field. So the resulting field would contain
Good coder, good unit tester
knowledge of multiple languages
weak at debugging code written by other developers
It seems to me that this should work but it doesn't.
{{issue.description.match("Strengths/Weaknesses: (.*?)Preferred Location:")}}
Other simple extractions like getting the Name work fine.
{{issue.description.split('\n').match("Name: (.*)").first}}
Looking for pointers...
Hi @Jeff Gordon
How about this: replace the newlines first to simplify the matches?
{{issue.description.replaceAll("(\n)"," ").match(".*Strengths/Weaknesses:(.*)Preferred Location.*")}}
This would remove the line formatting, although you can work-around that by replacing with a character/string as a token (e.g., NEWLINE) and then replacing back at the end to actual \n
Kind regards,
Bill
This gets me closer. Just to make sure I'm getting at least something I changed it to...
{{issue.description.replaceAll("(\n)","NEWLINE").match("Strengths/Weaknesses: (.*)")}}
...so it should grab everything after "Strengths/Weaknesses: "
But it only grabs up to where the first occurrence of NEWLINE would be per the replaceAll. I.e.,
Good coder, good unit tester
I added this to the log expecting all words to be butted against either side of NEWLINE
{{issue.description.replaceAll("(\n)","NEWLINE")}}
The result however is as shown below with something (a newline?) before each NEWLINE.
Name: My Name NEWLINETitle: My Title NEWLINEStrengths/Weaknesses: Good coder, good unit tester NEWLINEknowledge of multiple languages NEWLINEweak at debugging code written by other developers NEWLINEWork Location: The Beach NEWLINEDocumentation Status: Pending
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First thing, which I should have noted earlier: I am using Jira Cloud, and not Server/Data Center. And we know the automation features are different for those products. So please experiment/validate what I describe to confirm it works for you. Thanks!
Okay, I just tried this version and it worked exactly how I wanted to detect and preserve the multi-line content for the strengths/weaknesses:
{{issue.description.replaceAll("(\n)","NEWLINE").match(".*Strengths/Weaknesses:(.*)Preferred Location.*").replace("NEWLINE","\n")}}
Please note I explicitly added the extra character wildcards (.*) in my regular expression to handle content which leads/trails your grouping match.
When I tested I did not see an extra space added before "NEWLINE", and so that appears to be a difference between Cloud and Server/Data Center.
So if this one does not work for you, I suggest working with your site admin to submit a ticket to Atlassian Support to take a look. I do not see anything different in the documentation for Server/Data Center automation that would explain this symptom, so it may be an implementation difference for regular expressions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here's what finally worked in Jira Data Center.
{{issue.description.replaceAll("(\n)","NEWLINE").replaceAll("(\s+NEWLINE)","NEWLINE").match("Strengths/Weaknesses: (.*)Preferred Location:").replaceAll("(NEWLINE)","\n")}}
Seems like the first replaceAll does in fact leave a space in there and that somehow influences the match. So I had to replace " NEWLINE" with just "NEWLINE".
Appreciate the quick responses Bill and ultimate guidance to get to the solution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am glad you got that to work. You may want to let the support team know as that appears to be a defect in the regular expression implementation for Server/Data Center rules.
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.
And subsequently I realized that Description has embedded "\r\n". So the better solution ended up being...
{{issue.description.replaceAll("(\r\n)","NEWLINE").match("Strengths/Weaknesses: (.*)Preferred Location:").replaceAll("(NEWLINE)","\n")}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yup...carriage return and line feed (newline) vs. just the line feed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi folks, I have something like this in my description field (received via E-mailed ticket)
Please complete the following questions to enable us to resolve your incident.
*Name: Customer's Provided Name
*Urgency (High, Medium, or Low): High
I have written this code in my Additional Fields section of the automation rule to extract the text that the user has entered for the Urgency field (e.g. High):
{
"fields": {
"Urgency" : {"value" : {{issue.description.split('\n').match("\*Urgency (High, Medium, or Low): (.*)").first}} }
}
}
Its failing saying it is not a valid JSON.
However, the below is working fine to extract the text provided for Name:
{
"fields": {
"Email-Sender-Name":"{{issue.description.split('\n').match("\*Name: (.*)").first}}"
}
}
Any suggestions ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I didn't try it but you may need to escape the literal parens
match("\*Urgency \(High, Medium, or Low\):.(*)"
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.
I'd think that the '/' character which comes from the field name "Strengths/Weaknesses:" and appears in your regex pattern may be the problem. It is a special character.
You could maybe try a shorter pattern like:
{{issue.description.match("Weaknesses: (.*?)Preferred Location:")}}
If it works, at least you identified the root case.
Then, you can either use this shorter pattern, or use the original one but escape the '/' in it!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the suggestion but I don't think that is causing the problem. See comments below.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.