Automation for Jira - Writing a rule that checks if a date time field is within business hours

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

In some cases, it might be helpful to check if the value of a Date Time Custom Field is within a certain range of hours, for example within business hours (9:00-17:00). While Automation For Jira does not provide a way to extract the time portion of a Date Time custom field, there is a way to perform time comparison from a Date Time custom field, using the withHour smart value documented in this documentation.

This knowledge article provides an example of an automation rule that performs some actions based on the time range of a Date Time Custom Field.

Solution

Let's assume that you are trying to transition any newly created Jira issue to a different status, based on the value of a Date Time Custom Field. For example:

  • If the Date Time Custom Field is within business hours (for example 9:00-17:00), the issue should transition to Status 1

  • If the Date Time Custom Field is outside business hours, the issue should transition to Status 2

The solution for this use case consists of 2 main steps.

Step 1 - Identify the ID of the Date Time custom field

Let's identify the custom field ID of the Date Time custom field:

  • Go to the page ⚙ > Issues > Custom Fields

  • Search for the Date Time custom field

  • Click on... > View next to the field

  • Pickup the ID at the end of the URL (this is the custom field ID)

Step 2 - Create the automation rule

Now it's time to create the automation rule:

  • Add a new Trigger: Issue created

  • Add a new If/Else block

  • Inside the If block

    • Add a new Advanced Compare Condition

      • First Value (replace XXXXX with the custom field ID identified earlier):

        1 customfield_XXXXX.isAfter(customfield_12200.withHour(9))

      • Condition: equals

      • Second value: true

    • Add another Advanced Compare Condition

      • First Value (replace XXXXX with the custom field ID identified earlier):

        1 customfield_XXXXX.isBefore(customfield_12200.withHour(17))
      • Condition: equals

      • Second value: true

    • Add a New Action: Transition issue

      • Use the transition of your choice (Status 1)

  • Inside the Else block

    • Add a New Action: Transition issue

      • Use the transition of your choice (Status 2)

Screenshot of the rule

Final rule screenshot

Updated on June 6, 2024

Still need help?

The Atlassian Community is here for you.