Automation for Jira - a rule that is meant to edit the same field multiple times is not working

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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

As explained in the 2 KB articles below, it is possible to create a rule that add values to an existing field which can take multiple values (such as Components, Labels, Request Participants, Organizations...) without overwriting/deleting the values that the field already contains. To achieve this, the variable Copy from Issue needs to be used in the Edit Issue action:

While this type of rule works well when a field is only edited once, this rule does not work properly when the same field is edited multiple times by the same rule.

Diagnosis

Example

Let's take the automation rule from the screenshot below as an example:

screenshot of the automation rule

This automation rule is meant to add a value to the Organizations field in either or both of 2 IF blocks, depending on the content of the Labels field. With such rule, the following will happen:

  • Success: If a Jira issue only verifies the condition from the 1st IF block, the Organizations field will be updated only once, and it will contain the right value

  • Failure: if a Jira issue verifies the condition from both of the 2 IF blocks, the Organizations field will be updated twice, and while it should contain 2 values, it will only contain the value that comes from the 2nd IF block.

If we take a look at a Jira issue that was updated twice by this automation rule, we will see the following:

  • only the organization from the 2nd IF block was added to the Organizations field

  • the issue history shows that the organization from the 1st IF block was added, but it got later replaced by the one from the 2nd IF block

Ticket history

Cause

The reason why the automation rule does not work as expected when the same field is updated twice is because of how the Copy From Issue variable works.

This variable only contains the field values of an issue at the time the automation rule was triggered. Because of that, if the field is updated at least once within the automation rule:

  • the Copy From Issue variable will contain outdated information next time it is used in an Edit Issue action

  • whatever update was made to that field will be lost the 2nd time this field is updated within the same rule

Solution

To ensure that automation rules that edits the same field multiple times are working as expected, it is necessary to use the Re-fetch issue data action (which is described in the documentation Jira automation actions). This action will reload/refresh all the fields from the Jira issue, to ensure that the rule contains the most up to date value of all the Jira fields. Ultimately, this will ensure that the Copy From Issue variable is up to date.

The Re-fetch issue data action needs to be added right before the 2nd time, 3rd time, 4th time, etc... the same field is updated. It is not necessary to add it before the 1st time the field is updated.

Example

Taking the example of automation rule described above, this automation rule needs to be modified by adding the Re-fetch issue data action just above the 2nd time the Organizations field is updated:

  • The automation rule will look like this:

Re-fetch issue data
  • The Jira issue updated by this automation will include the 2 organizations added by the automation rule:

Automation result

Updated on May 31, 2024

Still need help?

The Atlassian Community is here for you.