Correct way to store date difference to a custom field using automation for Jira.

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

Summary

When working with Jira automation, storing the difference in dates between a custom field and the due date in a new custom field requires a smart value. The formula for this operation is {{issue.customfield_10189.diff(issue.duedate).prettyPrint}}. However, caution must be exercised when choosing the type of the new custom field, as certain types can lead to errors.

Diagnosis

In Jira automation, it is common to want to calculate and store the difference in dates between a custom field and the due date of an issue. The smart value mentioned above provides an elegant solution for obtaining this date difference. However, when trying to store this result in a new custom field, the field type becomes crucial.

Cause

Choosing an inappropriate field type for the custom field where the date difference is to be stored can result in errors. If a field of type 'Number' or 'Date Picker' is selected, Jira may encounter difficulties converting the result, which is a combination of both a number and text (e.g., "20 days").

Solution

To successfully store the date difference, follow these steps:

  1. Create a Text Custom Field:

    • Navigate to Jira Settings > Issues > Custom fields.

    • Click on "Add Custom Field" and select "Text Field" as the type.

  2. Configure Automation Rule:

    • Set up an automation rule that triggers when needed.

    • Use the smart value {{issue.customfield_10189.diff(issue.duedate).prettyPrint}} within the rule to calculate the date difference.

  3. Store Result in Text Field:

    • In the automation rule, add an action to set the value of the newly created text custom field with the smart value result.

By choosing a 'Text' field type for the custom field, you ensure compatibility with the mixed-format result ("20 days"), preventing conversion errors.

If we try to store the data in Number field we can get error "Could not convert the field value to a number. Please ensure the value is a number, math expression, or smart-value that can be converted into a number", when the result is on minus (Example -4).

Screenshot of Automation Rule:

Find difference in days between two dates using automation and store in Text field

Updated on May 31, 2024

Still need help?

The Atlassian Community is here for you.