Using RegEx to copy data from an Email Request and copying data into a custom field

Tyler Stephens April 6, 2021

Project - Reference Number: XX1-0111-AAProject - Version:

Trying to get the underlined number copied into a custom field:

RegEx: {{issue.description.match("(?<=Reference\sNumber:\s).*?(?=Project)")}}

Screen Shot 2021-04-06 at 12.57.15 PM.pngScreen Shot 2021-04-06 at 12.57.47 PM.png

1 answer

0 votes
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.
April 7, 2021

Hi @Tyler Stephens  -- Welcome to the Atlassian Community!

What is happening when you run your rule?  And, what are you seeing in the audit log?

Best regards,

Bill

Tyler Stephens April 7, 2021

Hey @Bill Sheboy

Thank you! 

When I run the rule, the audit log shows it being successful and the field being successfully modified. However, the field is still left blank. 

Thanks,

Tyler Stephens

 

Screen Shot 2021-04-07 at 3.06.27 PM.png

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.
April 7, 2021

Thanks for that information.  Given no errors in the audit log, I wonder if either:

  • your RegEx is too complex for the rule engine parser to handle
  • your RegEx doesn't match anything, and so evaluates to EMPTY

Maybe try writing with the Log Action to the audit log, gradually building up your RegEx until it stops working.  For example, add log lines for:

  • {{issue.description}}
  • {{issue.description.match(".*(Reference Number.*Project).*")}}
  • etc.

Note that you may need to use a suffix replace() function at the end to remove extraneous text if you only want the reference number in the custom field.

What do you think?

One note: If you have typos in your RegEx which cannot be parsed, the publish function for rules can hang/time-out.  So consider incrementally making changes so you can always fallback to an earlier version if you need to exit the rule editor.

 

Tyler Stephens April 8, 2021

Hey Bill,

I took your advice of using 

  • {{issue.description.match(".*(Reference Number.*Project).*")}}

and I discovered that it is pulling the styling elements of the email, so this must be what is interfering with my RegEx. 

I need to figure out a way to remove the styling elements from an Email Request now...

Thanks for your help!

Tyler Stephens

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.
April 8, 2021

You may want to check on Stack Overflow, as there are some examples and gotchas for removing styling elements with RegEx.  You could also get close with RegEx, and then use the automation rule text functions to remove/replace remaining elements.

Please post what you learn as others in the community will no doubt be interested.  Thanks!

Suggest an answer

Log in or Sign up to answer