This template displays the number of days that the current work item spent in the previous status.
If there is no previous status because the work item has never been transitioned to a new one, โNoneโ will be displayed.
Configuration
To use the Days in previous status template, simply select it from the template grid. Filter by Status to find it faster.
Parameters
This template does not require any additional parameter configuration.
Expert mode
If you switch to Expert mode you can see the formula field in the Expression Parser. You can now tweak the expression to create a custom formula field based on this template.
Expression
Jira expression:
let statusChangelogs = issue.changelogs.filter(changelog => changelog.items.some(item => item.fieldId == 'status'));
statusChangelogs[0] ? (statusChangelogs[0].created.getTime() - (statusChangelogs[1] ? statusChangelogs[1].created : issue.created).getTime()) / (24*60*60*1000) : null
Display as
Number
Formatting style
Default (unformatted)
Details
1. What does the expression do?
This expression calculates the number of days that the current work item spent in its previous status. If the work item has never changed status, the field displays โNoneโ.
2. Step-by-step breakdown
Letโs break it down:
-
issue.changelogs: This is a list of all changes made to the work item. -
.filter(changelog => changelog.items.some(item => item.fieldId == 'status')): This filters the changelogs to only those where the status field was changed. -
let statusChangelogs = ...: Stores the filtered list of status changes in a variable calledstatusChangelogs. -
statusChangelogs[0]: The most recent status change (the last time the status was updated). -
statusChangelogs[1]: The previous status change (the one before the most recent). -
statusChangelogs[0].created.getTime(): The exact time (in milliseconds) when the most recent status change happened. -
statusChangelogs[1] ? statusChangelogs[1].created : issue.created: If there is a previous status change, use its time; otherwise, use the time when the work item was created. -
The difference between these two times is divided by
(24*60*60*1000)to convert milliseconds to days. -
If there are no status changes, the expression returns
null(which is displayed as โNoneโ).
3. Examples
-
If a work item was created on January 1st, moved to a new status on January 5th, and then moved again on January 10th:
-
The expression will calculate the days between January 5th and January 10th (5 days).
-
-
If a work item has never changed status:
-
The expression returns null.
-
4. Real-life use cases
-
Tracking time in review: You want to know how long a work item spent in the "In Review" status after moving to "Done".