Automation: AQL branching issue
Asked by Tomislav Tobijas:

#### What are we trying to achieve? {#toc-hId-294965920}

We have employee IT equipment stored inside Assets. On each asset/object, you have an attribute stating current employee/owner of that asset. What our Asset managers would like to 'see' is when they navigate to 'people' object, to see which assets they have previously owned, together with assets they currently own.

Regarding assets they previously owned, the idea is to have additional attribute on each asset pointing to "people" object type that can also store multiple values as asset can be owned by multiple people during its existence.

#### The setup {#toc-hId--1512488543}

We are looking at two object schemas - one for people/users with 1 object type "People", and one for IT assets containing multiple object types (e.g., "Laptops", "Mobile phones"...)![image.png](/t5/image/serverpage/image-id/302963iE84165D9E300E107/image-dimensions/406x192?v=v2 "image.png")

?Additionally, have an **automation** in our JSM project which automatically updates current owner (removes the user from the IT asset attribute) once ticket (request type "Return your asset(s)) reaches specific status in a workflow.

#### The issue {#toc-hId-975024290}

Imagine that the JSM ticket has 2 objects (let's call them **Object 1** and **Object 2** ) linked and I'm owner of both of these objects. Both of these objects had previous owners where "Object 1" had **Person A** as a previous owner and **Object 2** had **Person B** as previous owner.

Now, the automation should do the following - once ticket reaches specific status, remove current owners from both objects (this part works okay), and change the value of **Previous owner(s)** attribute by only adding "current" owner to the list. So, after the automation is done, we should have something like this:

* Object 1 ("Previous owner(s)"): **Person A, Tomislav Tobijas**
* Object 2 ("Previous owner(s)"): **Person B, Tomislav Tobijas**

Automation is using the following solution for appending the values to object attribute: <https://confluence.atlassian.com/jirakb/how-to-append-objects-to-an-assets-object-attribute-using-automation-1283493731.html>

![2024-01-29_11-40-19.png](/t5/image/serverpage/image-id/302987iEFA57257559C3778/image-size/large?v=v2&px=999 "2024-01-29_11-40-19.png")

Now, according to rule logs, created variable is correct upon creating but once it is used in **Edit Assets field attribute** action, it updates both objects with 'same' values and I end up with the following result:

* Object 1 ("Previous owner(s)"): **Person A, Tomislav Tobijas**
* Object 2 ("Previous owner(s)"): **++Person A++, Tomislav Tobijas** (? not ok)

![2024-01-29_12-03-14.png](/t5/image/serverpage/image-id/302991iC63F809D4C940CC9/image-size/large?v=v2&px=999 "2024-01-29_12-03-14.png")

I'm wondering if I'm missing something here? Does the automation and (AQL) branching work in a way that if there are multiple objects inside branch:

1. Iteration 1: For object 1 \> create variable
2. Iteration 1: For object 1 \> update attributes
3. Iteration 2: For object 2 \> create variable
4. Iteration 2: For object 2 \> update attributes

Or does it work in some other mysterious ways? ?

Any help would be appreciated ?  
Cheers!


Answers:
author: Bill Sheboy
body: Hi [@Tomislav Tobijas](/t5/user/viewprofilepage/user-id/3848395)

First thing, a disclaimer: I am not using JSM or assets with rules, and so my suggestions are based on what I know about rules and not those products / features of Jira.

Inside the branch, your rule appears to create a variable with the same name twice in a row, although I cannot see the details of the value being set. What is the purpose of those actions?

Until that is clarified...

Please note that branches which could process more than one thing are run in parallel and asynchronously. And there is no guarantee of when the branch will complete, up to the last step of the rule.

What this means is things which happen inside that type of branch stay inside of there, and cease to exist outside of each iteration / loop. The exception is anything written / saved to the cloud. If you are expecting that variable to persist and be updated, that cannot happen.

Kind regards,  
Bill

comments: author: Tomislav Tobijas
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) my apologies then for dragging you into this!

Regarding this:
> *Inside the branch, your rule appears to create a variable with the same name twice in a row, although I cannot see the details of the value being set. What is the purpose of those actions?*

In the first action, we just wanted to 'reset' the variable to see how the system will behave. **Feel free to ignore this part** **as I've removed this first *Create variable* action and left only the 'second' one (stated in original post).**

![2024-02-06_09-30-29.png](https://community.atlassian.com/t5/image/serverpage/image-id/304548iC8BC6FCBE9631469/image-size/large?v=v2&px=999 "2024-02-06_09-30-29.png")

When it comes to this:
> *What this means is things which happen inside that type of branch stay inside of there, and cease to exist outside of each iteration / loop.*

In my case, it seems that variables from different branches somehow overlap (at least that's how I see it) and there is no clear pattern when or how it works. When you have two objects where "Previous owner(s)" are the same people, it works okay. But when they are different users (whether one or multiple), I usually get different results. I've tested multiple iterations where I've changed "Previous owner(s)" values and here are the results: <https://koios.atlassian.net/wiki/external/MTk4ZGQyMGJkNmY2NGYyYzg1OTk3ZjlhNzFkNmQ0MDg>

One more thing - can you clarify this?
> *The exception is anything written / saved to the cloud.*

Cheers,  
Tom


author: Bill Sheboy
body: The values of variables for each iteration / loop of the branch on the AQL are definitely distinct. If the values overlap, that would be related to:

* the AQL used for the branch (and so the objects returned), and / or
* the smart value expression used to create the variable

And so the double updates you note are likely caused by the overlap, and the unpredictability of results from the parallel processing nature of loops.

The solution is to somehow adjust those two things above to process each item one time.

About this...
> *The exception is anything written / saved to the cloud.*

If inside of a branch it updates an issue (or object) that persists, stored in the cloud. The other things inside of the branch (e.g. variables created) no longer exist after the branch runs each loop. Sorry if the original post was a bit vague :\^)


author: Tomislav Tobijas
body: Ugh... I can be such a potato-head sometimes ????

Before I added branching/iteration, the action for updating assets/objects was **Edit Assets field attributes**. As, initially, we only had one asset linked to an issue, that was fine. I forgot to take in consideration that this actually updates all assets in specified Jira field, even if there are multiple objects added.

Once the iteration was added, variable creation and branching was okay, but in each iteration, automation action would update both objects and not only the one from current iteration.  
Basically, the only thing I had to do is to replace mentioned action with **Edit object attributes** (which actually looks current object from branch iteration), and everything worked like a charm.![Replace action.png](https://community.atlassian.com/t5/image/serverpage/image-id/304720i3E531F847D0D02CD/image-size/large?v=v2&px=999 "Replace action.png")

[@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) , thanks for the help here! I needed second pair of eyes and the guidance you provided to resolve this. Much appreciated ?


author: Majken Longlade
body: Thanks for figuring this out, I was literally just trying to figure out the same thing!

The docs on using Automation with Assets are no where near sufficient.


author: Tomislav Tobijas
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) mind checking this out if you find the time?


Tags: automation

cloud

jira-service-management

jira-service-management-cloud