Forums

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

How to extract several lines from Description to set multi-line text field with Automation for Jira

Jeff Gordon
Contributor
March 8, 2023

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...

3 answers

1 accepted

1 vote
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2023

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

Jeff Gordon
Contributor
March 9, 2023

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

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 9, 2023

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.

Jeff Gordon
Contributor
March 9, 2023

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.

Like Bill Sheboy likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 9, 2023

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.

Like Mont likes this
Jeff Gordon
Contributor
March 9, 2023

Will do.

Jeff Gordon
Contributor
March 9, 2023

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")}}

Like Bill Sheboy likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 9, 2023

Yup...carriage return and line feed (newline) vs. just the line feed.

0 votes
Zeeshan Ahmed Khan
Contributor
March 17, 2023

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 ?

Jeff Gordon
Contributor
March 17, 2023

I didn't try it but you may need to escape the literal parens

match("\*Urgency \(High, Medium, or Low\):.(*)"
Zeeshan Ahmed Khan
Contributor
March 20, 2023

Got it. Thanks mate. All sorted now.

0 votes
Aron Gombas _Midori_
Community Champion
March 9, 2023

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!

Jeff Gordon
Contributor
March 9, 2023

Thank you for the suggestion but I don't think that is causing the problem.  See comments below.

Suggest an answer

Log in or Sign up to answer