Return the averaged time since the sub-tasks of the current work item were created in duration format.
Configuration
Create a Custom smart number field and use the General parsing mode.
Expression
%{floor(avg(toNumberList(jiraExpression("issue.subtasks.map(i=>(Number(new Date())-
Number(i.created)))"))))}
Display as
Duration
Formatting style
Long
Used parser functions
The links lead to the JWTC documentation because the parser functions are shared functionalities.
Details
1. What does the expression do?
This expression calculates the average amount of time that has passed since the sub-tasks of the current work item were created. The result is shown as a duration.
2. Step-by-step breakdown
Letโs break it down:
-
jiraExpression("issue.subtasks.map(i=>(Number(new Date())-
Number(i.created)))")-
This part uses a Jira expression to go through each sub-task of the current work item.
-
For each sub-task (
i), it calculates the difference between the current date/time (new Date()) and the sub-task's creation date (i.created).
-
-
toNumberList(...)-
Converts the list of values (one for each sub-task) into a list of numbers, ensuring they can be averaged.
-
-
avg(...)-
Calculates the average (mean) value from the list of numbers.
-
-
floor(...)-
Rounds the average down to the nearest whole number.
-
-
%{ ... }-
This syntax is used to interpret the elements within as functions.
-
3. Examples
Suppose a work item has three sub-tasks:
-
Sub-task 1 was created 10 days ago.
-
Sub-task 2 was created 5 days ago.
-
Sub-task 3 was created 15 days ago.
The expression will:
-
Calculate the time since creation for each sub-task in milliseconds (for demonstration purposes we will show them here as days and not milliseconds): [10, 5, 15]
-
Find the average: (10 + 5 + 15) / 3 = 10
-
Apply
floorand the necessary duration formatting: 10 days
So, the field will display "10 days".
4. Real-life use cases
-
Team performance tracking: Quickly see how long, on average, sub-tasks have been open for a work item, helping teams identify if tasks are lingering too long.
-
Process improvement: Identify bottlenecks by monitoring if sub-tasks are consistently taking longer to complete.
-
Reporting: Use this field in dashboards or reports to show the average age of sub-tasks for different work items, projects, or teams.