Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to auto-add watcher from the person at in the latest comment?

Craig Change September 3, 2021

I comment a jira as follows:

hi @Lily @[deleted]  it's a lovely day, isn't it?

 

I want to use jira automation to add lily and tom as the watchers, but don't know how to fulfill this. Could any guy help?

 

Thanks,

Craig

2 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.
September 3, 2021

Hi @Craig Change 

Until that suggestion is implemented, you could built this functionality yourself using Automation for Jira.  For example:

  • trigger: issue commented
  • action: create a variable, and use text functions and regular expressions to extract the mentioned users account id values
  • condition: advanced compare to check if there were any mentions
  • advanced branch: to iterate over the created variable as a list
    • action: add watchers for each mentioned user

 

To learn more about automation rules, please see this documentation and examples:

Kind regards,
Bill

Kit Friend
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 2, 2023

Hey @Bill Sheboy  - I'm a newbie to variable writing - do you have an example of what the action would look like here? We're trying to achieve the same thing

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.
February 2, 2023

Hi @Kit Friend 

Here are more details on what I described to extract the account id values from the comments...

  • trigger: issue commented
  • action: create variable...
    • name: varAddWatcher
    • smart value: 
{{issue.comments.last.body.replace("[~accountid"," [~accountid").split(" ").match("(accountid:.*)]").remove("accountid:")}}
  • advanced compare condition: check if {{varAddWatcher}} does not equal empty
  • advanced branch...
    • smart value: {{varAddWatcher.split(",")}}
    • variable name: varWatcher
      • action: manage watchers
        • add these watchers: {{varWatcher}}

Kind regards,
Bill

UPDATED 2023-Feb-06: I updated the expression for varAddWatcher to split on spaces before searching for the accountId values.

UPDATED 2023-Jun-15: In the unlikely case there is no leading space between mentions, I updated the smart value expression to add a space before mentions and then split on them.

 

Like # people like this
Kit Friend
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 5, 2023

Thanks @Bill Sheboy really kind of you!

Kit Friend
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 6, 2023

@Bill Sheboy have you had this working successfully for multiple users being tagged? It's working fine for me on single users, but errors when there's more than one. I'm wondering if it's to do with the initial variable creation action only creating the first one as a smart value...

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.
February 6, 2023

Hi @Kit Friend 

Here is the fix below.  This rule which I believed worked in the past stopped working when there were multiple mentions on the same text line.  The improvement below first splits the comment by spaces into separate lines, and then tests each entry to find the accountId.

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

I tested this successfully for a few scenarios; please let me know if you see any other problems with it.

Thanks,
Bill

Like Kit Friend likes this
Kit Friend
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 14, 2023

@Bill Sheboy  I've been getting a (low number of) persistent errors where if multiple mentions are on the same text line without spaces or any punctuation between them, the amended rule fails. Did this come up in your testing? 

 

i.e. this works fine: 
CleanShot 2023-06-14 at 17.03.49.png

 

but this fails: 

CleanShot 2023-06-14 at 17.03.55.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.
June 15, 2023

Hi @Kit Friend 

No, I had not tried that scenario...and it failed for me also.  I had to explicitly delete the space after the first mention to create this condition.

One work-around is to always ensure there is a space before the mention text and then split:

{{issue.comments.last.body.replace("[~accountid"," [~accountid").split(" ").match("(accountid:.*)]").remove("accountid:")}}

I will update my earlier answer to include this also.

Kind regards,
Bill

Mark Lendrum
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!
April 17, 2024

Thank you, very helpful

Mark Lendrum
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!
April 17, 2024

@Bill Sheboy The auto-add doesn't seem to work when I mention a user without any preceding text or space before the mention. If there is a space or word ("Hi") then it does work. Is there a way to achieve 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 17, 2024

Hi @Mark Lendrum -- Welcome to the Atlassian Community!

This scenario and solution approach has changed several times in community posts.  Please try this one:

{{issue.comment.last.body.split(" ").match("\[~accountid:(.*)\]").distinct}}

That will produce a list of unique user account id values that were mentioned.

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events