How to use "Advanced branching" properly to check a box for each value included in the smart value
Asked by Darren Nicas:

We have an internal incident ticket where automation and internal teams will create incident tickets using '*Affected service* s' field to indicate which services are affected then indicate on a checkboxes custom field \`*Impacted Services* \` where the same values names are available from both \`*Affected services* \` and \`*Impacted Services* \`. This allows cloning the ticket into downstream customer facing portals who have the indicated affected services in their contract and display the field to them in their respective tickets. This is in an effort to workaround the limitation of '*Affected services*' not usable by unlicensed service management users (aka customers).

The problem I'm facing is using the "Advanced Branching" automation block to iterate over each name of an '*Affected services* ' value. When I capture the '*Affected services*' as a smart value it is replacing each value of the 'Impacted Services' field, it thinks the field is empty each time it iterates on to the next value.

Am I using this correctly? Why doesn't it **add** the new values instead of starting empty each iteration? Is there some other way I can capture the list of all values from one field and transpose them to another field? I've tried the same with '*Labels* ' and it behaves the same starting with an empty '*Labels'* value for each iteration.

Here you can see it works fine with only 1 \`Affected services\` selected:

![Screenshot 2023-08-17 175126.png](https://community.atlassian.com/t5/image/serverpage/image-id/275834i2A5DAAE605DF27DF/image-size/large?v=v2&px=999 "Screenshot 2023-08-17 175126.png")

![Screenshot 2023-08-17 175240.png](https://community.atlassian.com/t5/image/serverpage/image-id/275833iA511338C19ADC7AF/image-size/large?v=v2&px=999 "Screenshot 2023-08-17 175240.png")

If I select more than 1 \`*Affected services*\` value it exhibits the unintended behavior, where you can see it tries to set the value twice, each time starting with a value of "None".

![Screenshot 2023-08-17 175437.png](https://community.atlassian.com/t5/image/serverpage/image-id/275832i9B989BDC64FD5D27/image-size/large?v=v2&px=999 "Screenshot 2023-08-17 175437.png")

![Screenshot 2023-08-17 180945.png](https://community.atlassian.com/t5/image/serverpage/image-id/275831i10E8B619E7508C86/image-size/large?v=v2&px=999 "Screenshot 2023-08-17 180945.png")

Here are some screenshots of the rule, the smart values and logging are just for debugging, the trigger is editing the issue to make for easier testing, but the same behavior is observed with create issue trigger as well.

![rule-43f8jja-4f3af.png](https://community.atlassian.com/t5/image/serverpage/image-id/275837i53695A87D8AD089F/image-size/large?v=v2&px=999 "rule-43f8jja-4f3af.png")


Answers:
author: Bill Sheboy
body: Hi [@Darren Nicas](/t5/user/viewprofilepage/user-id/5294405) -- Welcome to the Atlassian Community!

Yes, this scenario is solvable...but not with advanced branching.

First some information about branches in rules:

1. Branches on *one-and-only-thing* (e.g., Current Issue, Epic Parent, etc.) are run in-line, as if the branch did not exist. And so the rule flows as you have written it.
2. Branches which *could be on more than one thing* (e.g., Advanced branch, JQL, linked issues, etc.) are run in parallel and asynchronously. There is no guarantee when they will finish, up to the last step of the rule.

And so for your rule, the results are unpredictable, and the issue edits repeatedly walk-over each other.

For your scenario, a possible solution is to perform one single edit. Using text functions and a list iterator, create the JSON to perform the edit of the multiselect field, as described here: <https://support.atlassian.com/cloud-automation/docs/advanced-field-editing-using-json/#Multi-select-custom-field> And then use that JSON string in a single Edit Issue action.

I recommend first creating your JSON expression and writing it to the audit log until it works as you expect for all cases: 0, 1, \>1 values selected. Then you can add it to the edit.

Kind regards,  
Bill


author: Darryl Lee
body: Hi [@Darren Nicas](/t5/user/viewprofilepage/user-id/5294405) --

I was going to write something like what [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) wrote, but not as eloquently. :-}

I was thinking about the 2nd case though, and it is kind of odd that even though each edit action runs asynchronously, it seems highly unlikely to me that they'd run in exact sync, and since the JSON you're using is supposed to **add** a value rather than replace it, it's odd that you don't get at least *some* of the right values some of the time.

~~But anyways, yeah, you should be able to do this with a single Advanced Edit, using this handy [JSON function,](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-json-functions/) **asJsonObjectArray**. Something like this:~~

```
{ 
"fields": { 
   "customfield_10219" : {{issue.customfield_10033.name.asJsonObjectArray("name")}} 
}
```

~~++Dangit, should have tested first.++~~

~~++Of course Bill is right, and man, I feel like we tried this before somewhere and stupid Automation doesn't actually let you treat multi-select field values as actual lists, so I had to iterate through values, just like Bill recommended:++~~

```
{
"fields": {
"customfield_10219" : \[ {{#issue.customfield_10033}} { "value" : "{{.}}" } {{\^last}},{{/}} {{/}} \]
}
}
```

Haha I [went back and found when we I did this before](https://community.atlassian.com/t5/Jira-Core-Server-questions/How-to-add-copy-values-from-checkbox-to-labels-update-not-set/qaq-p/2255022#M62416), and once again I forgot how to use the dang function. In this case we want **value**, so this is super easy and clean:

```
{ 
"fields": { 
"customfield_10219" : {{issue.customfield_10033.asJsonObjectArray("value")}} 
}
```

comments: author: Bill Sheboy
body: Thanks, Darryl. I am going to start book marking these as stuff like this repeatedly comes up. And remember the possible "gotcha" noted in the earlier thread when the attribute names need to change between the field definition and attributes. (e.g., id versus value)


author: Darren Nicas
body: Thanks for the quick responses [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) , [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322) . Appreciate the comments, with both of them I was able to come to a solution that works for me :).

```
{
"fields": {
"customfield_10219": {{issue.customfield_10033.asJsonObjectArray("name").replace("\"name\"","\"value\"")}}
}
}
```


author: Darryl Lee
body: Ah, I forgot you were using **Affected Services** which is a special field from Insight so yeah, you need to use the **replace()** function *like I did before,*haha. So glad you figured it out.