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

Evaluating Else-if when If matches

I was changing an existing rule to add a few checks to limit the amount of "Success" executions. And I was puzzled at first. It turned out that a ticket matched the If-block, automation changed a custom field to a value that made the Else-if block match while at the start of the execution it didn't.

Now, I'm not a programmer, but I would have expected that if the If matches, it would stop evaluating Else-if. Which is not the case here.

So I was wondering, is this by design, or not? :) 

2 answers

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 04, 2023

Hi @Tom De Blende 

For a question like this, I recommend posting images of your complete rule (in one image) and of the audit log details showing the rule execution.  Those will provide context for the community to offer suggestions.  Thanks!

Until we see those...

Conditions in rules have two possible impacts on processing: stop or keep going.  And so the structure of the rule and conditions is important.  For example:

  • trigger...
  • condition...
    • some action

In this case, the action only happens if the condition is met.

  • trigger...
  • if/else condition 1...
    • some action A
  • else/if condition 2
    • some action B
  • else
    • some action C
  • some action D

For this one, only A or B or C will happen, followed by D happening.

Now here is a sometimes confusing part: rule processing is based on the issue data from the time the rule triggered.  And so if in the above case, "some action B" changed the issue data, those changes are not visible to the remainder of the rule.  When we want the changes to become visible to later processing, we add a Re-fetch Issue action to reload the data before continuing.

Other rule structures impact flow also, like this one

  • trigger...
  • branch...
    • condition 1...
      • some action
  • condition 2...
    • some action

In this case, condition 1 does not stop rule processing if it is not met...because it is contained within the branch.  Instead it just stops further branch processing for that loop.

Again, seeing your rule structure will provide context to help explain what you are observing.

 

Kind regards,
Bill

Well, it's like this:

Custom Field is set to False

  • trigger (comment is made)
  • if conditions :
    • Initiator is not X AND 
    • Custom Field is not set to True...
      • Set Custom Field to True
  • else-if condition 
    • Custom Field is not set to False...
      • Set Custom Field to False

What happens is this: 

If matches, because the field is set to False. Action taken: custom field is now True.

Now I would (like you) expect the rule processing to stop. But it doesn't. It goes to the else-if and says: ah, Custom Field is not set to False (it was changed to True in the If block), so I need to set to False. Which was not the intention at all! 

So this tells me that rule processing does not use issue data from when the rule was triggered. And that not A or B happen, but both!

This is what the rule looked like:

image.png

This is what the execution looked like:

image.png

How I solved it:

Custom Field is set to False

  • trigger (comment is made)
  • if conditions :
    • Initiator is not X AND 
    • Custom Field is not set to True...
      • Set Custom Field to True
  • else-if condition 
    • Initiator is X AND 
    • Custom Field is not set to False...
      • Set Custom Field to False

So I added a new condition to the Else-if so that it would not match the state that was created in the If-block.

I hope this made sense :)

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 04, 2023

It appears there is some image capture issue with your rule.  Regardless...the rule image you show does not match the text description of your rule:

  • the image shows two tests on the Initiator in the first if/else block
  • but the text description shows one test on Initiator and one on the custom field

I wonder if there was a problem with the initial rule conditions.

Hi Bill,

I was wrong. Explaining the whole logic to you and diving deeper into it helped a lot in finding my error :)

The first If block was not hit, because a new condition was added. And because it was not hit, the Else-if was hit, while it shouldn't have been.

Thanks a lot for your time!

Like Bill Sheboy likes this
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 05, 2023

Gotcha; is it working as you expected now?

Like a charn! ;)

Like Bill Sheboy likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events