Questions on correctly setting variables with regex

Ben Hart May 2, 2024

I have the following steps within a single rule:

1. Create variable - {{firstName}}

smart value - {{issue.comments.last.body.match("[A-Za-z]+(?=\.)(?=\.\w+\@jamf\.com)").capitalize()}}

 

2. Create Variable - {{lastName}}

smart value - {{issue.comments.last.body.match("(?<=\w+\.)[A-Za-z]+(?=\@jamf\.com)").capitalize()}}

 

3. Create Variable - {{fullName}}

{{firstName}} {{lastName}}

 

I validated the regex using two different regex sites.. but neither matches on the comment body:

 

"Alert LMD873080672 status changed: ack ----- Alert lbextd01.fluff.net/LinuxNewProcesses-/opt/cisco/amp/bin/ampdaemon/Status is acknowledged by ben.hart@fluff.com

 

Previously I had a variable being defined by: {{issue.comments.last.body.match("(\w+\.\w+(?=@))").replace(".", " ")}}. And it worked great! But I need the first and last name variables with proper capitalization in order to use them to assign Incidents. I can't think of a better way other than splitting it, and using .capitalize on each, then recombine them.

Maybe Jira doesn't like Positive lookbehinds?

 

What am I doing wrong here?

2 answers

1 accepted

0 votes
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.
May 2, 2024

Hi @Ben Hart 

Are you trying to assign the issue using the user name with a Jira Cloud automation rule?  If so, that is not possible: the rule will need to use the account ID value for the user.

To get the account ID from the user name, the rule would need to call the REST API user search function using the Send Web Request action.

Kind regards,
Bill

Ben Hart May 3, 2024

Hey Bill.. So help me understand please. If I add a `Then: Assign the issue to` step. I tried both; assign issue to smart value and specify user.  Both of which accept a smart value as a value. So what you are saying is, that won't or is not supposed to work?

Ben Hart May 3, 2024

After looking further.. I see the mention that JQL queries can no longer use the dusplay name but user id instead, due to GDPR.  But I see nothing in print so far that tells me you cannot assign an issue from a smart value of a users name/dispalyName.

However.. because time is fading and I'm a super anxious person I am now experimenting with a lookup table for name -> id.

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.
May 3, 2024

Yes, this is a GDPR change impact.  For Jira Cloud, I believe the current options are:

 

Like Ben Hart likes this
Ben Hart May 3, 2024

Gotcha.. well just to be sure then am I correct in understanding that you can call/reference lookup table keys using smart values?

For example, creating a variable {{fullName}} from {{issue.comments.last.body.match("(\w+\.\w+(?=@))"}}

Which would equal bob.smith, who is also a key in the lookuptable, `bob.smith`.

Then assign the issue to - {{assignTable.get("{{fullName}}"}}

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.
May 3, 2024

Almost...there is no need for the quotation marks around the name or the extra curly brackets.

{{assignTable.get(fullName)}}

 

Like Ben Hart likes this
Ben Hart May 3, 2024

Oh snap.  Works like a champ! Much and many thanks Bill!

 

How did you get to know this product so well?

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.
May 3, 2024

Awesome; I am glad to learn that helped!

For learning, I recommend lots of experimentation in test projects...writing things to the audit log, and reading community posts.  Those help fill in the gaps from the documentation.

Like Ben Hart likes this
Ben Hart May 3, 2024

Understood, thanks again!

 

0 votes
Ben Hart May 2, 2024

I found another, older post where someone was asking something VERY similar. But it worked. Basically I set the initial variable using:

{{issue.comments.last.body.match("(\w+\.\w+(?=@))").replace(".", " ")}}

 

Then use a second one with:

{{fullName.split(" ").capitalize().join(" ")}}

 

Works like a champ! Except now the rule still fails to assign but it's reportedly a permissions issue now. Ill start a new post for that one.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events