Get the amount of time a Jira issue was in a status using automation
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
Please note that in Jira Data Center, units of work are called "issues," and in Jira Cloud, the same units are called "work items." These are functionally the same, but this article refers to them as "issues."
Using two separate Jira automation rules, we can track how much time an issue was in a status. Our example covers a status named Pending, but it can be used to track any status that has been set on a workflow.
There are three steps needed to calculate the time in a status.
Create a custom field to store the date/time an issue enters a status
Create an automation rule to update this custom field with the timestamp of transitions into the status
Create an automation rule to compare the time an issue transitions out of the status with the time it entered
The Automation for Jira (A4J) rule components in the following rules are available and will work in Jira Cloud and in Data Center and Server versions using A4J 9.0.3 or higher.
Optionally, we can calculate cumulative time in status as well. To store the cumulative time the Jira issue spent in Pending status (if it enters the same status more than once during the issue life cycle), we will need an additional Number type custom field to store the cumulative time. This is described in a separate section titled "Optional: Calculate cumulative time in status."
Solution
Create a custom field to store the timestamp
We will need a new custom field to store the time an issue enters the Pending status. Choose the Date Time Picker field type.
In our example, we name this field Time in Pending. The field stores the number of seconds the issue was in the Pending status. We can also get time in days, hours, and weeks, as detailed in the following steps.
Create an automation rule to store date and time of transition
The finished automation rule will look as diagrammed below:
Rule name: Store time issue enters Pending status
From status: leave blank
To status: Pending
Rule trigger: Issue transitioned
Rule action: Edit issue
Choose fields to set:
Time in Pending
Field value:
{{now}}
Save and publish your new rule. When this rule is run, the Time in Pending field will store the date and time the issue entered the Pending status.
Create an automation rule to calculate the time spent in a status
The important part of this step is the first rule action, which is to Create a variable. This variable (named NumberOfSeconds in our example) will store the time difference between the date/time the issue was transitioned to the Pending status, and the date/time the issue left that status.
Our variable should use the smart value {{Time in Pending.diff(now).seconds}}
We can then post the value of the NumberOfSeconds variable as a comment on the issue using a second rule action.
Here is our finished rule diagram:
Rule name: Calculate and report time spent in Pending status
From status: Pending
To status: leave blank
Rule trigger: Issue transitioned
Rule action: Create variable
Variable name: NumberOfSeconds
Smart value:
{{Time in Pending.diff(now).seconds}}
Rule action: Comment on issue
Comment: This issue was in Pending status for
{{NumberOfSeconds}}
seconds.
If you prefer, you can choose to use the NumberOfSeconds variable in other rule actions including the Send Email action.
Our smart value can contain units other than .seconds
, including: millis, minutes, hours, days, weeks, months, years, and businessDays
More details and examples are available here.
Optional: Calculate cumulative time in status
If issues move into Pending status more than once, for example:
Created → In Progress → Pending (1 day) → In Progress → Pending (2 days) → Done → Closed
The above cumulative time spent in Pending is 3 days. We'll have to save and append the time spent during each instance of the issue transitioning and leaving the Pending state into a Number type custom field.
We can accomplish this with the following steps:
Create a Number type custom field to store the total time spent in Pending
In our example, the field is named TotalPendingSeconds
Add a new action to the calculating automation rule (the second one) to increment the Number field with the following math expression:
{{#=}}{{NumberOfSeconds}} + {{IF(TotalPendingSeconds,TotalPendingSeconds,0)}}{{/}}
The reason we use the IF math function is to cover the edge case where the TotalPendingSeconds field is EMPTY (null) in cases where the default value of this field is not zero. The Smart Value math operator '+' will fail if one of the operand's value is EMPTY.
Additional resources:
Currently, for Jira Data Center, there is the Jira Charting plugin that provides limited Time in Status tracking for issues. There is a feature request to expand its functionality, JRASERVER-29214.
Was this helpful?