For Branch Not Functioning as a Loop
Asked by Christian:

I'm having an issue using using the for branch that stems from it not functioning as a loop, but rather trying to action everything at once.

I have an automation that uses a for branch to look at all linked issues, and then pull a specific field from linked issues and write them to a filed on the trigger issue, with values being separated by commas. The field would already have a value in it, so the additional values would be added with the initial value. My initial idea to do this was to create a for branch that looked at each linked issue, get the field value, and then write to the trigger issue field taking the initial value and appending on the comma and new values. If the for branch functioned as a loop, this would work. However, I found out it does not loop through the actions, and instead tries to action each element at once. The results was the values not writing properly. Below is the issue history when I ran this (The original value is 109, and I want to 187 and 269):

![Screenshot 2024-06-18 093919.png](/t5/image/serverpage/image-id/330409i94CFF98ECB43B2E0/image-size/large?v=v2&px=999 "Screenshot 2024-06-18 093919.png")

My next idea to fix this is to instead write this to a label field, instead of a text field. Label fields have an "add" function, so I thought it wouldn't matter that multiple values would be added at the same time. However, I found that this still had issues. In this example, I want to add labels 269, 114, 187, and 268 to a custom label field that starts empty.

![Screenshot 2024-06-18 094616.png](/t5/image/serverpage/image-id/330412iC5695C51B393E399/image-size/large?v=v2&px=999 "Screenshot 2024-06-18 094616.png")

It appears that the "Add New" function does something similar to what I was doing in the previous example, where it looks at what the current labels added are and copies them into it and adds the new one. It still has the problem of when multiple adds are being done at the same time, it does not capture all of them.

I am wondering if there is a better way to achieve what I am looking to do. If there was a way to make the for branch function as a loop, this would solve my problem. Other creative ideas are most welcome.

Thanks!

Christian


Answers:
author: Bill Sheboy
body: Hi [@Christian](/t5/user/viewprofilepage/user-id/5412859)

For a question like this, please post an image of your complete automation rule, images of any relevant actions / conditions / branches, an image of the audit log details showing the rule execution, and explain what is not working as expected. Those will provide context for the community to offer ideas. Thanks!

Until we see those...

Automation rule branches which could be on more than one thing are run in parallel and asynchronously. In fact, there is no guarantee of when the branch will complete up until the last step of the rule.

For your scenario, each update of the trigger issue is walking over (or colliding with) other updates.

One possible solution for your specific scenario would be:

* use the Lookup Issues action to gather the linked issues
* use list iteration to concatenate the values

For example to concatenate a single text field from the issues, the expression could be this:

```
{{lookupIssues.myCustomField.join(", ")}}
```

Seeing your rule and knowing more about your custom field will help clarify the solution approach.

Kind regards,  
Bill


author: Aron Gombas _Midori_
body: It seems concurrently updating those fields is a source of problems.

Instead, maybe you could "pre-calculate" the string you are looking for and store that in smart value using the "Create variable" action. And at the end of the execution write the smart value to the field.

If "Create value" has a better concurrency control, then it may work...


Tags: cloud

jira-cloud