Add smart value list of users to multi user select field
Asked by Devlend Maul:

When a new comment is created on an issue and one or more users are mentioned, I would like those users added to a multi user picker field. I can extract something that looks like an user id list but it only works when there is one user id. I think my issue has to do with improper formatting of the list so the smart value branch runs for each item. Any assistance would be greatly appreciated. Thanks.

Extracts ids from comment and adds a comma after each id

![automation_image_1.png](/t5/image/serverpage/image-id/338938i9FA39CA3E381CA6B/image-size/large?v=v2&px=999 "automation_image_1.png")

Removes last comma and splits extracted string ids to create a list

![automation_image_2.png](/t5/image/serverpage/image-id/338940i9D6CBF8EA30D6747/image-size/large?v=v2&px=999 "automation_image_2.png")

Smart value branch to run on each item in list

![automation_image_3.png](/t5/image/serverpage/image-id/338941iB29328F29C288336/image-size/large?v=v2&px=999 "automation_image_3.png")

Adds the user id to the multi user picker field

![automation_image_4.png](/t5/image/serverpage/image-id/338942iE97B182008716A27/image-size/large?v=v2&px=999 "automation_image_4.png")

Success log when only one user is mentioned.

![automation_image_log_1_user.png](/t5/image/serverpage/image-id/338954i9E911172A132BA2A/image-size/large?v=v2&px=999 "automation_image_log_1_user.png")

Error log when two or more users are mentioned.

![automation_image_log_2_users.png](/t5/image/serverpage/image-id/338952i107CD2FFC2D55C73/image-size/large?v=v2&px=999 "automation_image_log_2_users.png")


Answers:
author: Marco Calluso
body: Hi [@Devlend Maul](/t5/user/viewprofilepage/user-id/5132175)

I had a similar issue. It kinda worked for me, when I put the ".split(",")" in the "Smart Values" field of the advanced branching.  
Like this:  
![Screenshot 2024-09-09 145010.png](https://community.atlassian.com/t5/image/serverpage/image-id/346326iE7016510C92CBE38/image-size/large?v=v2&px=999 "Screenshot 2024-09-09 145010.png")

I guess this is because the advanced branching isnt treating the variable like a list and when you put the split there it will treat it like one.  
But I still have a Problem with the multi picker. Because for me right now it always overwrite the multi picker instead of adding the user to the existing ones.

I hope this helps and maybe you can tell me, if you have the same problem with the overwriting.

Best regards

comments: author: Bill Sheboy
body: Hi [@Marco Calluso](/t5/user/viewprofilepage/user-id/5539737)

For the multiple-selection field symptom you describe, the fix is to not use branching (as that runs in parallel and will walk-over prior results).

Instead use a single issue edit with using JSON to add the values with advanced edit: <https://support.atlassian.com/cloud-automation/docs/advanced-field-editing-using-json/#Multi-select-custom-field>

You may use list iterators on the values from your created variable to pre-build the JSON needed in the issue edit, and write that to the audit log to confirm the format is correct.

Kind regards,  
Bill


author: Bill Sheboy
body: Hi [@Devlend Maul](/t5/user/viewprofilepage/user-id/5132175)

The match() function does not handle text with newlines, and other formatting, well for fields like Comments and Description.

One workaround to get better matches is to add a split(" ") immediately before the match() call, as that will reduce the scope the regular expression tries to search. For example, here is one I have used which also removes any duplicate mentions in the same comment, creating a CSV list of the account id values.

```
{{issue.comment.last.body.split(" ").match("\[~accountid:(.++)\]").distinct.join(",")}}
```

If you know you have many newlines you may also want to add this before the split:

```
replace("\n"," ")
```

Kind regards,  
Bill

comments: author: Devlend Maul
body: Thanks for the additional info. But before I start adding improvements I first need to solve for having the advanced branching iterate over smart value list of the Ids. As stated before, when there is only one id in the list it works but when you add another it doesn't. Let me know if there is any thing else I can share that would be helpful. Thanks.


author: Bill Sheboy
body: Hi [@Devlend Maul](/t5/user/viewprofilepage/user-id/5132175)

Sorry for the delay in responding as I have been offline for a few weeks.

Did you try the expression I suggested? That will first split() on spaces to reduce the scope of the match() and produce a list of user account id values.

Then you will need to use an [iterator of that list](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/#Combined-function-examples) to create dynamic JSON to add the values *in one edit action rather than with branching* : <https://support.atlassian.com/cloud-automation/docs/advanced-field-editing-using-json/#Multi-user-picker-custom-field>

Perhaps like this:

```
{
  "update": {
    "customfield_11768": [
      {{#varListOfAccountIdValues.split(",")}}
        { "add": {"id":"{{.}}"} } {{^last}}, {{/}}
      {{/}}
    ]
  }
}
```


Tags: cloud

cloud-automation

jira-cloud