Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

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

 

1 answer

1 accepted

1 vote
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.
Oct 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

{{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.
Oct 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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events