Return the date of the last time that the status of the current work item was changed.
If it was never changed, return the creation date.
Configuration
Create a Custom smart text field and use the Jira expression parsing mode.
Expression
issue.changelogs.filter(changelog => changelog.items.some(item => item.fieldId ==
'status')).map(changelog => changelog.created).concat(issue.created)[0].toString()
Details
1. What does the expression do?
This expression returns the date when the status of the current work item was last changed. If the status has never been changed, it returns the creation date of the work item.
2. Step-by-step breakdown
Let's break it down:
-
issue.changelogs: This retrieves the full history of changes (changelogs) for the current work item. -
.filter(changelog => changelog.items.some(item => item.fieldId == 'status')): This filters the changelogs to only include those where the status field was changed. -
.map(changelog => changelog.created): This converts the filtered changelogs into a list of their creation dates (i.e., when each status change happened). -
.concat(issue.created): This adds the work item's creation date to the end of the list. This is important in case there were no status changes; the creation date will be used as a fallback. -
[0]: This selects the first date in the list. Because changelogs are ordered from most recent to oldest, this will be the date of the last status change, or the creation date if there were no status changes. -
.toString(): This converts the date to a string format for display.
3. Examples
-
If a work item was created on January 1st and its status was changed on January 5th and January 10th at 9 AM, the expression will return "10/Jan/25 9:00 AM" (the last status change).
-
If a work item was created on February 1st at 9 AM and its status was never changed, the expression will return "1/Feb/25 9:00 AM" (the creation date).
4. Real-life use cases
-
Displaying the last time a work item moved to a new status, such as from "In Progress" to "Done".
-
Tracking how long a work item has been in its current status by comparing the current date to the last status change date.
-
Reporting or filtering work items that have not changed status for a certain period, to identify items that may be stuck or need attention.