Finding Mentioning a User in Comment ... and Custom Field User Picker (multiple users) check
Asked by Christoph Schulz:

* Finding the Mentioning of a User / s in last Comment

than add to...(Watcher...or a Custom Field...) adding leads to another question

* Costum Field User Picker (multiple users) check difference

check if a user already got a mail, it is used for group works since its a custom field user wont get notified. i managed to inform them via comment or email spam everytime the value of picker changes.

But it would be much better if i could just sent a message to the last person/s added an email and avoid duplicates.

Iam not sure how i can split the picker and check for values.


Answers:
author: Bill Sheboy
body: Hi [@Christoph Schulz](/t5/user/viewprofilepage/user-id/5187401)

Your scenario seems to be: *when someone is mentioned in a comment the first time, I want to add them as a Watcher (or to a Custom Field), and send them an email. When the user is mention again later I do not want to add them to the field again or send another email.*

Does that sound correct?

For a question like this, I recommend posting images of your complete current rule and the audit log details showing the rule execution. Those will provide context for the community to offer suggestions.

Without that information...

It appears you have already learned how to find and extract and account ID value from a comment mention. If you pull out all possible mentions from the last comment, your rule could use an advanced branch to iterate over them. Then use an advanced compare condition to determine if they are already listed as a Watcher (or in the Custom Field), and only proceed if they do not exist yet in the field.

Kind regards,  
Bill

comments: author: Christoph Schulz
body: Almost yes,

iam struggling at this part "how to find and extract and account ID value from a comment mention."

So my Automation would start like Task commented, find the mentioning, than use the account ID for an email or add as a watcher.  
(Task commented \> compare {{issue.comments.last.body}} has \[\~accountid: )

The custom field, i have trouble with the many account IDs it saves. So when an Automation starts i have all the accounts, and i will send them all an email even if they were before inside of the custom field.

Yes an advanced compare, to figure out the difference between the newest vaule of the field and the last in a log i guess. I want to subtract the accounts which are doubled to get the unique ones and sent them a mail to inform them, you are on the task.


author: Bill Sheboy
body: Would you please post images of your complete current rule, and show the details of your branch and advanced compare condition, and of the audit log details showing the rule execution? Those may provide more context for making suggestions. Thanks!


author: Christoph Schulz
body: ![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/258846i6689D2CAD42C9406/image-size/large?v=v2&px=999 "image.png")


author: Bill Sheboy
body: Let's try this one piece by piece...

First, mentions in comments store only the account ID for a user. To find all of the users mentioned in the last comment, the expression below works. It would split a comment into lines, find mentions, and then extract the account id values.

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

That can produce a list of the users, and so they must be iterated over in an advanced branch.

For your scenario, you only want to email the users who are not already watching the issue...and so they must be tested, one by one. And so an example rule would be:

* trigger: issue commented
* action: create variable
  * variable name: varAddWatcher
  * smart value: {{issue.comments.last.body.split(" ").match("(accountid:.\*)\]").remove("accountid:")}}
* advanced compare condition:
  * first value: {{varAddWatcher}}
  * condition: does not equal
  * second value: leave as empty
* advanced branch:
  * smart value:{{varAddWatcher.split(",")}}
  * variable name: varWatcher
    * advanced compare condition:
      * first value: {{issue.watchers}}
      * condition: does not contain
      * second value: {{varWatcher}}
    * action: add watcher, {{varWatcher}}


author: Christoph Schulz
body: Exactly this ?

Perfect!

Thank you for the lesson and continue to support.

.


author: Bill Sheboy
body: Awesome! I am glad to learn that helped, and also...

Using automation rules often requires both experimentation and learning. To help with those I recommend building skills by:

* look at the examples in the [template library](https://www.atlassian.com/software/jira/automation-template-library#/rule-list?systemLabelId=all&customLabelId=1453&page=1&pageSize=20&sortKey=name&sortOrder=ASC) to learn how they solved problems
* look at posts/examples in the community to see if others have already solved a problem you are trying to address...this can be tricky, as people describe things differently, so I recommend using a web search to find the posts in the community :\^)
* create a test project (at least) or a free Jira instance (at better) to experiment and "break things" while trying out rules.
* regularly go look at the documentation pages, as they continue to improve over time
* think outside the box: often rules cannot solve a "problem" and pausing to consider why something is needed may reveal a better solution

Happy experimenting!


author: Marcel Rossouw
body: This automation rule works like a charm - the only downside is that even if no new mentions are made, the rule runs as a 'success' with message:

##### {{smart values}} condition {#toc-hId--1475208204}

The following issues did not match the condition:  

With Jira software rolling out automation cap/limits is there a way for this rule to be updated to only be successful when a mentioned user is actually tagged in a comment? In other words this rule will trigger any comment made on tickets and mark it as a 'success' greatly increasing the amount of times the automation rule runs.


author: Christoph Schulz
body: The lowest amount of rule runs would be trigger manualy.

or via Date/Time event window.


author: Marcel Rossouw
body: Yeah, only way around is if it strictly matches a JQL query condition however not sure you can target all users for comment/description field. CurrentUser() exists but not a catchall parameter for all other mentioned users to use in a JQL query.


author: Christoph Schulz
body: Before Iam totaly stuck .. is there an **easy** way to get Email changed in a custom Field ? otherwise would i have to add @ domain and remove, replace everything around the display name ? But i will run into display name is not the full name in mail problems..

[@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

My tries are

1 {{addedfieldChange.valueIds}} id numbers   
11 {{addedfieldChange.valueIds.emailAddress}}

<br />

2 {{addedfieldChange.emailAddress}}

<br />

3 {{addedfieldChange.values}} display names  
33 {{addedfieldChange.values.emailAddress}}

4 {{fieldChange.to}} \[list of id numbers\]  
44 {{fieldChange.toemailAddress}}  
444 {{fieldChange.to.emailAddress}}

5 {{fieldChange.fromemailAddress}}

8 {{changelog.customfield_10034}} only custom field name worked   
88 {{changelog.customfield_10034.emailAddress}}

9 {{customfield_10034}}  
99 {{customfield_10034.emailAddress}} this worked but it gives me old and new  

9999 {{customfield_10034.last.emailAddress}} just last email  
99999 {{customfield_10034.addedfieldChange.to.emailAddress}}  
999999 99999 {{customfield_10034.addedfieldChange.emailAddress}}

comments: author: Bill Sheboy
body: Hi [@Christoph Schulz](/t5/user/viewprofilepage/user-id/5187401)

I recommend starting with the changelog to learn what is available for your field. Remember changelog will only include the fields which changed during an edit, and perhaps not other cases.

{{#changelog.yourCustomField}}{{fromString}}{{/}}

And the current value should be in the {{toString}}

Regarding the differences between the email address, displayName, and full name, you may not have access to that unless you are using a Jira user field (with an accoundId).

Kind regards,  
Bill


author: Christoph Schulz
body: Hello @\[deleted\]

It's a User Picker (multiple users) called Mitwirkende Personen

I would like to sent an email to Omar Darboe in this example

thats the changelog written in the task  
Christoph Schulz hat Folgendes aktualisiert: Mitwirkende Personen 28. Juni 2023 um 15:15 \[Chat Notifications, Jie Yan Song\]----\[Chat Notifications, Jie Yan Song, Omar Darboe\]

{{changelog.Mitwirkende Personen}}

ChangeItemBean{fieldId='customfield_10034', field='Mitwirkende Personen',fieldType='null',from='\[5b70c8b80fd0ac05d389f5e9, qm:b81e873f-658f-47e0-b05b-48fec4419b59:75b1855b-71eb-4000-93f4-b0f1f081015d\]',fromString='\[Chat Notifications, Jie Yan Song\]',to='\[5b70c8b80fd0ac05d389f5e9, qm:b81e873f-658f-47e0-b05b-48fec4419b59:75b1855b-71eb-4000-93f4-b0f1f081015d, qm:b81e873f-658f-47e0-b05b-48fec4419b59:a1654234-e66e-4113-82ba-0ff38c8b6400\]',toString='\[Chat Notifications, Jie Yan Song, Omar Darboe\]'}  

{{#changelog.Mitwirkende Personen}}{{fromString}}{{/}}

\[Chat Notifications, Jie Yan Song\] {{toString}}

{{addedfieldChange.valueIds}} qm:b81e873f-658f-47e0-b05b-48fec4419b59:a1654234-e66e-4113-82ba-0ff38c8b6400

{{addedfieldChange.values}} Omar Darboe


author: Christoph Schulz
body: can i set up a tempory or hidden user field in background that fills in only the changed value and sent an email to them ? and after that its done it will clear the data again... shouldnt be this the easiest way ?

it will have the ids, no need to edit anything. the only thing is i need to take care of is that nobody would touch that field.

like a cache


author: Bill Sheboy
body: You could use an entity property for that; rules can set/read them and they would not be on the screen.

Would you explain further: why do you need to save the value when you want to notify the changed users each time?


author: Christoph Schulz
body: The Email only accepts people fields, if i use it on all Mitwirkende Personen it would result in spam to people who were inside the Field before.

i've tried sent the mail to {{addedfieldChange.valueIds}} but it said its empty so.. i guess it's the only way to save it, is in a new field ?

""You could use an entity property for that; rules can set/read them and they would not be on the screen."" Not sure how this works ive tried use my account as property for the key and the value but it can't the mail to the {{key}} because its empty ????


author: Christoph Schulz
body: sorry didn't read why, the custom field has no notification by default (like assign) the people get added and the project leader would have to write a comment or sent a group mail to inform them.

That's too complicated.. so i try to automate an easier way, also that other people can understand what i did.. if iam out of office and have to troubleshoot it.

Not sure if the Team Field will get notification soon.


author: Christoph Schulz
body: But sometimes there are random people from 2 teams so it probably has to be a custom field.


author: Christoph Schulz
body: custom requests like this are difficult [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) .. maybe i need to convince them its easier to use watchers since its an integrated feature and could sent notifications and ... all by default.

watcher is a user field or ?


author: Bill Sheboy
body: Yes, the watcher field is a multi-select user field.