Forums

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

If a user is mentionned in a comment, add it as watcher (data center)

Garn August 21, 2024

Hi,

 

My goal is to add as watcher the first person tagged in a comment (no iterative branch in this case). I'm in a data center instance.

automation watcher.png

I followed the recommendation from Bill in this topic : 

https://community.atlassian.com/t5/Jira-questions/Automation-Help-Add-watcher-when-user-mentioned-in-comments/qaq-p/2121329

 

I have done a test by creating a comment with my coworker tagged "Test Automation @mycoworker" and checked in the audit log : the @mycoworker is not recognized.

It looks like the smart value is not working for me:

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

 

automation watcher 2.png

 

 

Any help on this please?

Thanks,

Regards

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.
August 21, 2024

Hi @Garn 

First thing, I am using Jira Cloud and not Data Center, and so please test the solutions I offer with your site.

The other question you linked to uses a solution approach for Jira Cloud, which includes a user's account id to implement a mention.  However, I believe Jira Server and Data Center use a different mechanism with the user name.

Let's confirm that with your test rule: add a write to the audit log with this:

last comment body: {{issue.comments.last.body}}

Test your rule and review the log.  I suspect the entry looks like this:

last comment body: here is my comment mentioning [~billsheboy] in the sentence

If that is the case, you may adjust the match() and remove() function parameters accordingly.

Kind regards,
Bill

Garn August 22, 2024

Hi Bill,

Thank you for your help! 

It displays:

last comment body: Test Watcher [~201034280]   

With 201034280 being the identifier of the user.

Could you please share what it looks like in cloud so I can understand how to adjust match and remove functions please?

 

Thanks,

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.
August 22, 2024

Thanks for testing that!

For Jira Cloud, the mentions work like this, where 12345abcde would be the user's Atlassian account identifier:

[~accountid:12345abcde

And so a change for your version to get the user identifier could be this:

{{issue.comments.last.body.split(" ").match("(\[~.*\])").substringBetween("[~","]")}}

Please test this for your instance. 

Garn August 22, 2024

Yes, thanks, we're almost there!

Now I have an error on the manage watchers action:

automation watcher 4.png

 

In my action, I'm adding as watcher my variable {{addwatchers}}

automation watcher 3.png

 

Do you have any clue on the error right here? 

Thank you,

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.
August 23, 2024

I do not recognize that error message.  Let's check on some things to narrow down that symptom...

First, check if the user mentioned can be added manually to the issue as a watcher, and then remove them.

 

Next, modify your write to the audit log for the variable to this and retest.  This will identify if there are any stray characters leading / following the user identifier.  If there are, they may be removed with the trim() function added to the end.

addwatchers: ZZ{{addwatchers}}ZZ

 

Finally, let's try to set the watch using the user display name.  This will confirm if the watcher cannot be set with the user identifier in a rule action.

To try this, copy the Create Variable action and in the second one, later in the rule, set the value to the exact display name for the user.

Garn August 26, 2024

Hi Bill,

 

I confirm that I can manually add the user on the ticket.

 

I have updated the audit log with : addwatchers: ZZ{{addwatchers}}ZZ

The updated audit log displays :

Log action

Log
addwatchers: ZZ201034280ZZ


 

I have created two variables: 

watcher : ~201034280

watchertwo : 201034280

watcher three : FirstName LastName(201034280)

 

And the audit log: 

watcher : {{watcher}} -- {{watchertwo}} ----- {{watcherthree}}

 

Please find the results with the same error:

automation watcher.png

Garn September 2, 2024

@Bill Sheboy any idea?

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 9, 2024

Hi @Garn 

Sorry for the delay in responding as I have been offline for a few weeks.

Thanks for confirming what the variable contains, as the one with just the id should work in the action.  (Unless those ids in Jira Data Center are numbers...in which case conversion is needed with asNumber.)

Would you please post an image of your current, complete rule and an image of the action where you Create Variable and where you use that with Manage Watchers?

Garn September 10, 2024

Yes, let me give you here the different codes for variables and the audit log to ease the understanding:

aut1.png

Variables:
addwatchers : {{issue.comments.last.body.split(" ").match("(\[~.*\])").substringBetween("[~","]")}}

asNumber : {{issue.comments.last.body.split(" ").match("(\[~.*\])").substringBetween("[~","]").asNumber}}

 

aut2.png

audit log2: add watchers: {{addwatchers}} ------- addwatchers with zz: ZZ{{addwatchers}}ZZ ---------- asNumber: {{asNumber}}

watcher : ~201034280

watchertwo : 201034280

watcherthree : Thomas AXXXXXXXXXX(201034280)

audit log3: watcher : {{watcher}} -- {{watchertwo}} ----- {{watcherthree}}

 

 

 

 

aut3.png

 

 

---- and now the audit log:

 

aut4.png

Looks like my asNumber is not working in the log action 2.

 

 

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 11, 2024

asNumber is a function and so I advise not using that as a variable name to avoid confusing the rule.

Next, you are trying to add multiple things at one time as watchers and so that could be causing challenges seeing what works, or does not.  Let's simplify to one single test and evaluate what happens:

  • trigger: issue commented
  • action: create variable:
    • name: varMentionedUsers
    • smart value:
{{issue.comments.last.body.split(" ").match("(\[~.*\])").substringBetween("[~","]").join(",")}}
  • action: write the created variable to the audit log
varMentionedUsers contains: {{varMentionedUsers}}
  • action: manage watchers, adding this:
{{varMentionedUsers.split(",")}}

 

Please note I explicitly added the join() and split() to avoid problems with the list being interpreted incorrectly.

Garn September 12, 2024

Hi Bill, 

 

Thank you a lot for your help and not giving up this topic 😅
Still the same error.

 

auto2.pngauto.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.
September 12, 2024

In the add watchers, please try using this instead:

{{varMentionedUsers.split(",").asNumber}}

That will confirm if a number is required (rather than text from the variable).

Garn September 16, 2024

Hi Bill, 

Still the same for me even with the change

 

Auto.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.
September 17, 2024

I am unclear why this is not working for your rule with a text (or a number) value for the watcher id.  And I am certain setting the watcher from a variable works for Cloud and for other posts I have seen for Data Center.

I recommend working with your Jira Site Admin to submit a ticket to the Atlassian Support team.  Perhaps they will see something we are missing.  https://support.atlassian.com/contact/#/

 

 

Suggest an answer

Log in or Sign up to answer