Hi Jira People,
I have the following problem which I hope you can help me with.
I would like to create an automation that basically does 2 things:
1. when the comment is added to the issue, the automation checks if there are any users mentioned there.
2. if a single or multiple users are mentioned, every single one of them is added to CC field.
Why such automation? I've employed Issue Security Scheme based on that field. As many times my users are mentioning users in the comment rather than putting them in CC field I would like to automate this process so that everyone is notified when someone mentions them (also they don't really see the issue before they're added to the CC field)
Now I've been partially successful as I did manage to create and automation which is capable of checking if there is any user mentioned in the comment. The problem is, if there is more than one user mentioned, the automation adds just one, not all of them.
My current partially working setup is this:
The trigger is simple: When: Issue Commented
Then I'm checking if the body of the last comment contains mentions
Then I'm branching out with Advanced branching
and for Smart Value
{{issue.comments.last.body.match("(\[~accountid:(.*?)\])").remove("[~accountid:").remove("]").asJsonObject("id")}}
I create a Variable smartUsers
Then Edit issue fields
{ "update": { "CC" : [ { "add": {{smartUsers}} } ] } }
I also added
and in the audit log I can see multiple user IDs, however the CC field is populated with just one and it's driving me crazy. Please help!
According to this documentation using smart values in a multi-user-picker takes a jsonObjectArray
A variable itself is always stored as a string. Therefore I would suggest to use the "asJsonObjectArray" (which you already used when creating the variable) in the real usage in your json (in your "Edit Issue" action)
Please let me know if this works.
Best
Stefan
Yes, and...to the suggestions from @Stefan Salzl
Rather than using the Advanced Branch, you may extract the mentioned users' account ID values and add them in one step, using inline iteration and dynamic JSON. This will reduce the risk of errors / racetrack problems due to the parallel processing of such branching.
Also...the match() function can have difficulty with this scenario when there are line breaks in a comment. I recommend using a split(" ") on the text before attempting the match:
{{issue.comment.last.body.split(" ").match("\[~accountid:(.*)\]").distinct}}
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you both for your suggestions, how would you recommend I rebuilt my entire solution then?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As a reminder, the Atlassian Community is a place for people to learn and collaborate, not to provide turnkey solutions for specific scenarios. I recommend trying the suggestions offered, including reviewing the docs, maybe writing intermediate results to the audit log, etc., to learn what helps.
For more details to what Stefan and I suggested:
Your field appears to be a multiple-select user field, and so the array JSON format is needed: https://support.atlassian.com/cloud-automation/docs/advanced-field-editing-using-json/#Multi-user-picker-custom-field
Smart values are name, spacing, and case-sensitive. And, they frequently do not exactly match the displayed name on the issue pages. When an incorrect smart value is used, that returns as null, often leading to rule errors / problems. I recommend pausing and using this how-to article to identify the correct smart value for your "CC" field, and perhaps the custom field ID, as needed: https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/
Any list may be processed using the long-format or inline iteration. To build the dynamic JSON, the long-format is better: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/#Combined-function-examples
The expression I provided earlier gives the unique, account ID values found in mentions. Those may be iterated to create the dynamic JSON. The example below is a fake custom field ID; please user your own value.
{
"update": {
"customfield_12346": [
{{#issue.comment.last.body.split(" ").match("\[~accountid:(.*)\]").distinct}}
{ "add": { "id":"{{.}}" } } {{^last}},{{/}}
{{/}}
]
}
}
In this expression, the {{.}} refers to the individual item found when iterating an untyped list (without attribute names), and a comma is conditionally added between the records added.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Bill, I understand that this is not a 'give me all the answers straight away and solve my issue' place. I do appreciate pointing me in the direction of those manuals. I'm frustrated with a half working solution so hopefully with what you suggested I'll have a full solution. Thank you and Stefan one more time!
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.