How to make a rule that triggers an action when a user is mentioned in a comment?

Alex F
Contributor
April 6, 2020

I want to create a rule that, for example, makes a web request when a user is mentioned in a comment and I need to get the mentioned user's accountId from the comment. How to achieve this?

2 answers

1 accepted

3 votes
Answer accepted
Alex F
Contributor
April 7, 2020

Here is the answer:

To trigger an action when a comment contains (or does not) a mention you should use the following regular expression:

\[~accountid:.+\]

If you want a rule to trigger when a mention is present in a comment body, it should look like this:

Jira automation 2.png

If you want to extract accountId from the mention in the last comment you should use the following smart value:

{{issue.comments.last.body.match("(\[~accountid:.+\])").remove("[~accountid:").remove("]")}}

For example, you can use the smart value in an email body or in a web request to Jira API.

Dorian Workman
Contributor
June 12, 2020

Hi there

This isn't working for me.  The automation rule audit log shows that the rule recognizes that a comment was added, but it doesn't seem to be recognizing the user mention.  Could this be something to do with how our mentions are displayed?  In our setup, when someone is mentioned their name is displayed in format Lastname, Firstname. We are on Jira Server v7.12.3.

Any suggestions please?

Thanks.

Alex F
Contributor
June 12, 2020

Hi,

I'm not sure it should work for Jira Server, I never used it, our deployment type is Cloud, so maybe you need to create a new question.

Dorian Workman
Contributor
June 12, 2020
Like Alex F likes this
zhangqian04
Contributor
June 23, 2020

please try  this regular expression:

\[\~.*?\]

Eva Pfister
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 19, 2021

Hey,
that works fine, perfekt.
Now I want, for example, send an E-Mail to that user. Has somebody an Idea how to proceed with the extracted accountId?

Thanks!

Alex F
Contributor
January 19, 2021

Hi @Eva Pfister,

I believe you should make a get request to the Jira API to get an email address for future reference. Here you can find how to do that. And here is the API endpoint you need.

You can access the email address from the API response with dot notation using the following smart value:

{{webhookResponse.body.emailAddress}}

Here you can find more about {{webhookResponse}} smart value.

Derek Kelsheimer
Contributor
August 1, 2023

This solution worked perfect. Thank you @Alex F!

Like Alex F likes this
0 votes
Alec Jasanovsky
Contributor
November 17, 2020

I was also having an issue using the format: 

\[~accountid:.+\]

 

Instead I was able to do this:

Screen Shot 2020-11-17 at 3.19.37 PM.png

Mohamed Darmoul June 14, 2023

Hello All , 

 Thank you for providing the solution on how to pick a mentioned user in a comment . Do you know how to pick multiple mentioned users in a comment and paste all of them in a multi-picker user field in a ticket ? 

Thanks for your help . 

Best ,

Mohamed

Thiago Schmid
Contributor
July 18, 2023

Hello everyone,

I have the same issues as Mohamed.

Using the below smart value works but only if one person is tagged in the comment and it does not update my user-pick field, instead it replaces the whole value with the new one.

{{issue.comments.last.body.match("(\[~accountid:.+\])").remove("[~accountid:").remove("]")}}

What I need is very much the above but that would get all IDs from the e.g. 3 people tagged in the last comment of an issue and add those people additional to the already existent value of the field.

I also tried the below smart value from another similar thread and that unfortunaty does not return any value when people are tagged.

{{issue.comments.last.body.split(" ").match("(accountId:.*)]").remove("accountId:")}}

Would that be possible, if yes how can I do it?

 

Thank you!

Thiago Schmid
Contributor
July 18, 2023

Okay, the Jira support team helped me find the solution I was looking for.

You can see the detailed information here.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events