If condition doesn't work as expected
Asked by Iana:

I have an automation rule with embeded "If-else" conditions within "If" conditions.

I expect the "if-else "conditions to be exclusive (if one is met, then the rest is not evaluated).

I expect the "If" conditions to be inclusive (even if the first "if" is met, the rest of the "If" is evaluated). Likewise, when the first "If" is not met, then the second "If" should be evaluated.

Below the image of most of my rule. When the rule is executed, it evaluates the first "if "(red arrow) and if it is met, it evaluates the "if-else". However it never actually gets to evaluate the second "if" (2nd red arrow).

Any ideas why?

![Automation1.png](https://community.atlassian.com/t5/image/serverpage/image-id/179919i61A8B9915155AA42/image-size/large?v=v2&px=999 "Automation1.png")


Answers:
author: Mykenna Cepek
body: The original post said:
> I have an automation rule with embeded "If-else" conditions within "If" conditions.

Actually, the rule you posted has a *series* of IF and IF-ELSE conditions. No conditions are "embedded" or nested. Jira Automation, to my knowledge, cannot nest conditions (although conditions may be used inside a branch).

Your rule is a linear series of steps. Regarding conditions:

* IF A THEN B ELSE C will execute either B or C, and then always continue after the condition.
* A simple IF will terminate the rule if the condition(s) it evaluates is false.

Hope that helps!

comments: author: Iana
body: Thanks for your reply Mykenna. That makes it clearer.   
I tried using the brach, but it won't allow if-else conditions.   
I need a rule with 2 levels of if-else conditions.

Is there any way to achieve that with automation?

Something like this:

If Field_1 is A then  
change_1.a  
If Field_1.1 is A.1 then  
change_1.a1  
else if Field_1.1 is A.2 then  
change_1.a2  
else  
change_1.a3  
else if Field_1 is B then  
change_1.b  
If Field_1.1 is B.1 then  
change_1.b1  
else if Field_1.1 is B.2 then  
change_1.b2  
else  
change_1.b3


author: Mykenna Cepek
body: Yes, you can achieve this in automation another way. (This is where my 20+ years as a software developer comes in handy...)

You can replace nested IF-THEN-ELSE conditions with a single IF-THEN-ELSE by adjusting the conditions appropriately. I've converted what you posted above to illustrate how to do that:

If (Field_1 is A) and (Field_1.1 is A.1) then  
change_1.a1  
else if (Field_1 is A) and (Field_1.1 is A.2) then  
change_1.a2  
else if (Field_1 is A) and (Field_1.1 is not A.1) and (Field_1.1 is not A.2) then  
change_1.a  
else if (Field_1 is B) and (Field_1.1 is B.1) then  
change_1.b1  
else if (Field_1 is B) and (Field_1.1 is B.2) then  
change_1.b2  
else if (Field_1 is B) and (Field_1.1 is not B.1) and (Field_1.1 is not B.2) then  
change_1.b


author: Manon Soubies-Camy
body: Hi [@Iana](/t5/user/viewprofilepage/user-id/4087588),

Automation is designed so that, if a condition fails, no actions following it will be performed. The "if/else" condition is actually an exception: if a condition fails, then we go to the next "else", then to the next one, and so on.

Hope this helps!

- Manon

comments: author: Iana
body: Thanks for clearing that out Manon!


author: Pramodh M
body: The second will not be evaluated, that is how it works

comments: author: Pramodh M
body: If any condition fails Automation will stop at that point!! Better use branching to separate the checks here for your requirement


author: Iana
body: Thanks for your reply. Do you have an idea on how I could have 2 levels of if-else conditions using the branching?


Tags: jira-server