Scheduled Automation rule with IF ELSE Block Condition not working as expected in Jira

Platform Notice: Cloud and Data Center - This article applies equally to both cloud and data center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

A scheduled Automation rule with the IF / ELSE Block Condition may require several executions to work as expected.

Diagnosis

The Automation rule has a Scheduled trigger (with JQL) and at least one IF / ELSE block, for example:

1 2 3 4 IF (condition A) THEN action A ELSE THEN action B

Or:

1 2 3 4 5 6 7 8 IF (condition A) THEN action A ELSE IF (condition B) THEN action B ELSE IF (condition C) THEN action C ELSE THEN action D
  • On the first execution of the rule, only "action A"is performed.

  • On the second execution of the rule, only action B is performed, or action A is performed again.

  • On the third execution of the rule, only action C is performed and so on.

  • It takes several consecutive executions to execute all actions of the IF / ELSE blocks.

Cause

This is actually the way the IF / ELSE Blocks work in Automation for Jira.

In Scheduled rules, the Conditions are applied to the set of Issues as fetched by the trigger JQL as a whole — opposite to iterating over each issue individually.

So, for a set of 10 issues if "condition A" results in non-empty, then "action A" is executed and the IF / ELSE block is done. If "condition A" results in an empty result, then if "condition B" results in non-empty, "action B"is performed and the whole Block is done.

This may be counter-intuitive to programmers, who may expect that each action would be applied to the given issues that match the respective conditions: 3 issues updated with action A, 2 issues updated with action B, 4 issues with action C, and so on.

We have the open improvement below to add this caveat to the documentation: JIRAAUTOSERVER-209 - Improve documentation on the IF ELSE condition behavior

Solution

One alternative is to use several IF / ELSE block separated from each other:

1 2 3 4 5 6 7 8 9 10 11 IF (condition A) THEN action A IF (condition B) THEN action B IF (condition C) THEN action C IF (condition "not A and not B and not C") THEN action D

The last "else" condition may be tricky as it would need to negate all other conditions in one.

Also, the conditions should be mutually exclusive, or else they need to negate the previous ones:

1 2 3 4 5 6 7 8 9 10 11 IF (condition A) THEN action A IF (condition B and not A) THEN action B IF (condition C and not A and not B) THEN action C IF (condition "not A and not B and not C") THEN action D

Visual example:

Automation rule visual

Updated on May 31, 2024

Still need help?

The Atlassian Community is here for you.