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

Still need help?

The Atlassian Community is here for you.

Ask the community

robotsnoindex

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server 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

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.

The purpose of this knowledge article is to provide an example of automation rule meant to perform some actions based on the time range of a Date Time Custom Field.

Environment

  • Jira Server / Data Center on any version from 8.0.0
  • Automation For Jira on any version from 7.4.0

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 in 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):

          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):

          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 showing the full automation rule



Last modified on Jul 12, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.