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}}"
}
}
]
}
}
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:
{{issue.comment.last.body.replace("\n", " ").split(" ").match("^\[~accountid:(.*)\].*").distinct.join(",")}}
{
"update": {
"custom_Field_10610": [
{{#varMentions.split(",")}}
{
"add": { "id": "{{.}}" }
} {{^last}},{{/}}
{{/}}
]
}
}
{{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.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.