In Jira Automation, Create Variable Value set in a loop does not seem to get set

Cash Coyne
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.
October 17, 2023

I have this situation: I'm trying to loop through some issues, ordered by assignee, and when the assignee is different from the last issue, I want to make an entry in the audit log (eventually will want to send an email)

I do a lookupissues with order by assignee (but i'm not sure the oreder by is working based on my results)

I create a variable LastUser to be "No User Given"

Then I branch on {{lookupIssues}}

I audit log the LastUser variable (and in the log, it shows it only ONCE)

Then I do an if to see if the {{LastUser}} == {{LookedupIssue.Assignee.DisplayName}} and if it does, I I audit log the {{LastUser}} and the {{LookedupIssue.Assignee.DisplayName}}

Then I create a variable LastUser to be {{LookedupIssue.Assignee.DisplayName}} which will be used as the comparison to the assignee DisplayName in the next iteration of the loop to see if I have yet another user.

But based on what I'm seeing, the LastUser is being set, but reverts back to "No User Given" at the beginning of the loop.

This is what I see in the audit log for showing the Last User at the beginning of the loop:

"Last User to Start is "No User Given" +++++"

And I see that once... shouldn't I see it multiple times in the audit log? Once for each iteration?

Then this is what I see prior to my if statement comparing the Assignee to the LastUser:

"Cur User is "Je Che", not Last user who is "No User Given" *****, Cur User is "Zhi Zho", not Last user who is "No User Given" *****, Cur User is "Alec Murry", not Last user who is "No User Given" *****"

So that looks like when I set the LastUser at the end of the loop, it didn't hold, because after I set it, I save it to the audit log and it looks OK:

Last User is now: "Je Che" !!!!! , Last User is now: "Zhi Zho" !!!!! , Last User is now: "Alec Murry" !!!!!

What am I doing wrong here?

I've included the screenshots of my Rule

Starting at the top:
image.png

 

Then inside the If statement:

image.png

 

2 answers

1 accepted

4 votes
Answer accepted
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.
October 17, 2023

Hi @Cash Coyne 

You are seeing the behavior of branches...

  1. Branches on one-and-only-one-thing (e.g., branch on current issue, on parent, etc.) get run inline, as if the branch did not exist.
  2. Branches which could be on more-than-one-thing (e.g. branch on JQL, advanced branches, etc.) are run in parallel and asynchronously.  There is no guarantee of when they will finish, up to the last step in the entire rule.

So, what are the impacts...stuff that happens in a rule of type #2 goes out of scope after the loop.  And so the create variable in your rule is brand new every time, and then thrown out.

There is an open suggestion to add a "wait until done" to branches, like for the Send Web Request.  As that might dramatically impact rule performance I wonder if it will be done.  Please look here to learn more: https://jira.atlassian.com/browse/AUTO-32

Anyways...

Without seeing your entire rule, I suspect you are trying to do something for each specific, distinct assignee found in the lookup.  And so a work-around for that scenario is to use the distinct list operator, like this:

  • trigger: some trigger
  • action: lookup issues with JQL
  • advanced branch: on {{lookupIssues.assignee.distinct}} naming the variable as varAssignee
    • action: lookup issues again with your original JQL, adding AND assignee = {{varAssignee.accountId}}
    • more steps...

Kind regards,
Bill

Cash Coyne
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.
October 17, 2023

{{lookupIssues.assignee.distinct}} is just what I need!  TYVM!

Can I ask where you found this referenced?  I looked in all the Jira documentation and I couldn't find the distinct described method anywhere except for a couple examples and only found them just now by knowing to look for the word "distinct".

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.
October 17, 2023

Awesome; I am glad to learn that helped!

Regarding branches, I have learned through experimentation, posts from the Atlassian team, and references in the help, such as this one: https://support.atlassian.com/cloud-automation/docs/jira-automation-branches/#Ordering-of-branch-executions

For the distinct function, that is in the help on the smart value lists: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/

I recommend periodically re-reading the help on actions, conditions, branches, and smart values.  Sometimes things appear there before they are released to prod  :^)

And perhaps watch the articles in the automation product area: https://community.atlassian.com/t5/Automation-articles/bg-p/automation-articles

One final thing: most of the stuff I have learned about rules has been from experimenting to answer my own questions and those of others.  The automation stuff is continually improving and so we cannot always rely upon the docs to stay current.

Like # people like this
Sidharth verma July 15, 2024

Hi Bill,

I am trying to do a similar thing and want to branch on AQL. I am able to query the assets using a query. however, it returns a list of objects and i want to access the first value of the object list.  How can i achieve that.

when i use : 

list.first

mentioned here:  https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/

it does not work as it is not recognizing the variable as a list variable. How can i assign the list of values that i get from an asset to a list variable so that i can access the first value of the list ?

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 15, 2024

Hi @Sidharth verma 

First thing, this is an older thread and so I recommend creating a new question to increase the visibility for the community to offer ideas.  When relevant, include a link back to the order question / thread for context.

Back to your question...

If you are branching on AQL, that is returning the list of matching objects and so you cannot access the first one found.  When you need to do that, perhaps try Lookup Objects.

If that does not help, I recommend creating a new question, including images of your complete rule, the relevant actions / branches, and of the audit log details.  Those will provide context to help.

Kind regards,
Bill

Sidharth verma July 17, 2024

Sure will do !!

Sidharth verma July 17, 2024

Hi @Bill Sheboy ,

 

I have posted a new thread with the topic name as "Loop over asset objects and update them using Jira Automation"

have mentioned all the details in that thread. Kindly have a look at it and respond if possible.

 

Thanks

0 votes
Sidharth verma July 15, 2024

 

 

Suggest an answer

Log in or Sign up to answer