Forums

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

How do I create a jira automation to leave a comment mentioning multiple users in a custom field?

Frank
Contributor
January 5, 2024

I have a custom user field called "Analyst(s)". This is a user field that sometimes only has one user in it or sometimes it might have a couple users in it.

What I want to do is create an automation that leaves a comment on the ticket when that ticket is transitioned to a certain status that @mentions all of the users in that custom field "Analyst(s)".

How do I do this?

1 answer

1 accepted

3 votes
Answer accepted
Mikael Sandberg
Community Champion
January 5, 2024

You can do that by getting the Atlassian Id for the users in that field via smart value and @ mention them like this:

[~accountId:{{user field name.accountId}}]

Note that if you have multiple users in that field you need to divide it up since you cannot use one [~accountid...] for all of them.

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.
January 7, 2024

Hi @Frank 

Adding to Mikael's answer...

When working with a multiple select user field, your rule may use the list iterator functions to add those mentions.  For example:

{{#issue.yourUserField.accountId}}[~accountId:{{.}}]{{^last}}, {{/}}{{/}}

To see other examples of list iterators, please look here:

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/#Combined-function-examples

Kind regards,
Bill

Like Frank likes this
Frank
Contributor
January 10, 2024

Thanks Bill this worked perfectly. Would you mind breaking down your answer to help me understand exactly what it's doing? I was confused on this portion in particular 

{{.}}]{{^last}}, {{/}}{{/}}
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.
January 10, 2024

Awesome; I am glad to learn that helped!

For more details on my suggestion...

The {{last}} and {{^last}} smart values are helpful when using a list, to add (or not add in the case of ^) things like a delimiter, as a suffix.  In my expression:

{{^last}}, {{/}}

This will add a comma-followed-by-a-space between each item, except the last one.  For your comment mentions, this makes it look nicer...but for other things like JSON and math expressions, this helps prevent syntax errors.

There is also a {{first}} operator when a prefix is needed for list values.

 

Regarding the {{.}} that is the placeholder for each item while iterating over the list.  And so for this expression

{{#issue.yourUserField.accountId}}[~accountId:{{.}}]{{^last}}, {{/}}{{/}}

Where we are iterating over any accountId values found in your multiple-select field, it is each value as we loop.

A less cryptic, way to do this would be this:

{{#issue.yourUserField}}[~accountId:{{accountId}}]{{^last}}, {{/}}{{/}}

That would iterate over the user objects selected in the field, and then use just the accountId attribute.  All of the other user attributes are available when using this method: displayName, emailAddress, etc.

 

That link I provided to the combined list examples show things not documented anywhere else for rules, so it may be worth a read to learn more  :^)

Steve Holland
Contributor
September 6, 2024

@Bill Sheboy  i tried a bunch of times in our sandbox but im screwing up the syntax...

same issue as above; we have a customfield (tester) thats a multi user picker...i just want the automation to @ the people listed in that custom field in a comment...here's my code...and the result i currently get without that list iterator stuff done right :)  Any guidance appreciated!

________________________________________________________________

{panel} *Automation Mention Final Test* {panel}


\\

* *Hardcoded:* [~accountId:6127b46f3ef46a007078ecf5] , [~accountId:6127b46f3ef46a007078ecf5]


* *Reporter:* [~accountid:{{issue.reporter.accountId}}]


* *Assignee:* [~accountid:{{issue.assignee.accountId}}]

* *Tester:* [~accountid:{{issue.customfield_49919.accountId}}]

\\
\\

Steve Holland
Contributor
September 6, 2024

2024-09-06_15-32-37.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 9, 2024

Hi @Steve Holland 

For a multiple-selection, user picker field an iterator must be used, as described in my earlier post.

If that does not help, please post images of your complete rule, the action where the mention happens, and of the audit log details showing the rule execution.  Those will provide context to help explain what you are observing.

Also, what version of Jira are you using: Cloud, Server, or Data Center?

Kind regards,
Bill

Steve Holland
Contributor
September 10, 2024

Thanks for the response @Bill Sheboy     its not that it didn't work, i just definateyl didn't do it correctly. it was a bit too "syntaxy" for me to be able to pull off :) 

 

  • We are on JIRA CLOUD
  • Audit logs show success and it is "succesful" as a rule, its just not printing what i would like for the results of that multiselect
  • below are the screenshots of the rule(simple just so i can test it) and its results that it produces and the log of success

runlog.pngjirarulerun.pngrule.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 11, 2024

What type of project is this: company-managed or team-managed?

And...for the multiple-selection user picker field Tester, please try this to mention all the selected users:

{{#issue.customfield_49919}}[~accountId:{{accountId}}]{{^last}}, {{/}}{{/}}

 Please note well: smart value expressions are case-sensitive, so confirm this exactly matches what you try.  (When the wrong case is used, the expression often evaluates to null and shows no errors.)

Steve Holland
Contributor
September 11, 2024

Its a company managed "instance" but team managed "Projects". Each project within the instance/tenant/whatever has its own admins that work on and deal with just that project, but there are overarching global admins if there is some post function or global access or multiproject thing needed. 

 

That worked @Bill Sheboy !   i must have originally screwed something up in the sysntax.  appreciate the help very very much!JIRAmentionmultiselect.png

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

Awesome; I am glad to learn it is working for you!

Like Steve Holland likes this

Suggest an answer

Log in or Sign up to answer