How to calculate the time spent on each status and total time on the issue
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Purpose
This automation provides a way to calculate the time in status for any issue. This can be used as a workaround to the limitation of not having a direct replacement of the time in the status trigger that is available in the legacy automation.
Solution
This automation is designed to work on the basis of the following workflow.
- According to this workflow, the issue can be resolved from any support level.
- Or it can be escalated to the next support level.
- In either case, the total time spent in the previous status will be calculated and stored in the system field belonging to that level.
- Since the issue can be reopened and can come back to support level one, therefore, the automation is designed to sum previous time with the current time and hence show the total time spent in the status in X number of iterations.
The custom fields shown in the snapshot will need to be created before the rule can be run. The field showing the time spent on each stage are of number type and the start date and end date are date type custom fields.
- The following expression is used to mark the entry and exit by recording the current time in the Australian time zone for any given status.
{{now.convertToTimeZone("Australia/Sydney")}}
- This automation calculates two kinds of totals. First, it calculates the time spent on each status, and secondly, it calculates the total time spent on the issue from start to finish. The following expression calculates the time in each status and the total time spent on the issue.
{{#=}}{{issue.Time Taken at User Testing}} + {{issue.End date cf.diff(issue.start date cf).abs.minutes}}{{/}} {{#=}}{{issue.Total Time Taken by All Support Levels}} + {{issue.End date cf.diff(issue.Start date cf).abs.minutes}}{{/}}
- The time difference is calculated using the status entry time and status exit time. To find the status that the issue was transitioned from the following smart expression is used
{{#changelog.status}}{{from}}{{/}}
- The status ID can be found by navigating to the global status page, https://your-site.atlassian.net/secure/admin/ViewStatuses.jspa, hovering the mouse over the edit link next to each status line and noting down the status ID in the URL appearing at the bottom of the page.
- Currently, the automation calculates the time in minutes but it can be easily changed to units mentioned in Calculating time difference
* Below is the snapshot of the rule. Download the rule JSON file automation-rule.json and import the rule to your site.