Forums

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

What is the smart value to extract account ids of the user from comments?

IT Brute November 21, 2025

We are on Jira Cloud.

I have automation rule that extracts the account id from the users mentioned in the comments and appends these users to the custom field. 

But this only works when the users are mentioned without any text in the comments, which of course defeats the purpose. 

This is something to do with regex in the smart value but I can't figure out. 

Smart Value : {{issue.comments.last.body.match("(accountid:[^]]+)").remove("accountid:").remove("[~").remove("]").split(" ")}}

Other thing is, that in the audit log it shows that the two user IDs were extracted but only one is appended to the field. 

Automation rule has advanced branching and for each smart value work item is edited. 

Here is the complete flow (with screenshots)

1. Work Item Commented - All Comments

2. Then create variable {{addUser}}

2.1 Smart value  {{issue.comments.last.body.match("(accountid:[^]]+)").remove("accountid:").remove("[~").remove("]").split(" ")}}

2.2 Add value to audit log - Just to see the output, this step can be eliminated 

3. For Each Smart Value: {{addSingleUser}}

3.1 Then:add value to audit log

3.2 Edit work item fields - More Options - JSON
{
"update": {
"customfield_10610": [
{
"add": {
"accountId": "{{addSingleUser}}"
}
}
]
}
}
Snipaste_2025-11-21_13-52-27.pngSnipaste_2025-11-21_14-05-00.png

2 answers

1 accepted

2 votes
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.
November 22, 2025

Hi @IT Brute 

Let's change your smart values and regular expression to parse only the distinct accountId values:

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

With that, we can eliminate the branching as that can cause update problems (due to racetrack errors when the branch processes asynchronously).  Instead, try a single Edit Work Item action with a dynamic JSON expression for the multiple-selection user field using iteration.

For example:

  • trigger: work item commented
  • action: create variable
    • variable name: varMentions
    • smart value:
{{issue.comment.last.body.replace("\n", " ").split(" ").match("^\[~accountid:(.*)\].*").distinct.join(",")}}
  • smart values condition: (This condition checks if there were any mentions before proceeding.)
    • first value: {{varMentions.split(",").size|0}}
    • condition: greater than
    • second value: 0
  • action: create variable
    • variable name: varJson
    • smart value:
{
"update": {
"custom_Field_10610": [
{{#varMentions.split(",")}}
{
"add": { "id": "{{.}}" }
} {{^last}},{{/}}
{{/}}
]
}
}
  • action: edit work item, with the advanced edit JSON as
{{varJson}}

 

Using a variable for the entire JSON expression prevents timing problems in the Edit Work Item action, and can help track down problems when JSON does not work as expected.

 

Kind regards,
Bill

 

UPDATE: fixed a typo in the varMentions variable.

IT Brute November 24, 2025

@Bill Sheboy 

@Bill Sheboy the smart value you provided 

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

has the same issue that it won't filter out the account Id if the comment is in the format of <text> <userName> <text> <userName>

Secondly, even when tested just with the userNames in the comments it won't append the values to the field. In Audit Log it shows the rule was successful but the user names was not added to the fields. I have attached audit logs of both the scenarios
Snipaste_2025-11-24_10-40-01.pngSnipaste_2025-11-24_10-40-28.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.
November 24, 2025

@IT Brute -- What version of Jira are you using: Cloud, Server, or Data Center?

Jira Cloud uses accountId value for mentions, while Server and Data Center use the user displayName.  In the comment it appears as the name, even though it is the accountId.

Or, do you mean when there are multiple mentions on a line of comment text, the expression does not parse them out correctly?

 

Next, let's confirm we are trying the same methods...

What is the type of the custom field you are trying to update, as I was using a multiple-selection user field?

Please post an image of the Create Variable action used to build the JSON.

Please post an image of the Edit Work Item action where you use the created variable.

 

Thanks!

IT Brute November 24, 2025

@Bill Sheboy  I resolved the issue. Had to some minor mends to your proposed solution.

1. Filter account ID from comments : I split this into two variables, in one I get the accountId with "accountid". This ensures the values are account ids and not the text of the comment.
varMentions = {{issue.comments.last.body.match("(accountid:[^]]+)")}}

2. In second variable I filter out unnecessary characters around account id 
singleUser = {{varMentions.remove("accountid:").remove("[~").remove("[").remove("]")}}

3. Third variable has the json as smart value to update the field, I edited this is little bit to get the "add" object in each iteration of the loop

varJson = { "update": { "customfield_10025": [ {{#singleUser.replace(" ", "").split(",")}} { "add": { "accountId": "{{.}}" } }{{^last}},{{/}} {{/}} ] } }

4. Edit work item: {{varJson}} under More Options

Like Bill Sheboy likes this
6 votes
arielei
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.
November 22, 2025

Hello @IT Brute 

Use {{addSingleUser.displayName}} for the user names.

Use {{addSingleUser.accountId}} if you want their Atlassian ID

 

Try it out and see.

Ariel.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events