Add smart value list of users to multi user select field

Devlend Maul July 30, 2024

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

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

automation_image_2.png

Smart value branch to run on each item in list

automation_image_3.png

Adds the user id to the multi user picker field

automation_image_4.png

Success log when only one user is mentioned.

automation_image_log_1_user.png

Error log when two or more users are mentioned.

automation_image_log_2_users.png

2 answers

0 votes
Marco Calluso
Contributor
September 9, 2024

Hi @Devlend Maul 

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

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

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 @Marco Calluso 

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

0 votes
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.
July 30, 2024

Hi @Devlend Maul 

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

Devlend Maul August 27, 2024

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.

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 @Devlend Maul 

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 to create dynamic JSON to add the values in one edit action rather than with branchinghttps://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}}, {{/}}
{{/}}
]
}
}

 

Suggest an answer

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

Atlassian Community Events