Time in statuses

πŸ“š

This template displays the total time the current issue has spent in a chosen set of statuses.

For the parameter Status, pick one or several Statuses, for which the time the issue spent in them will be summed up.

Configuration

To use the Time in statuses template, simply select it from the template grid. Filter by SLA, aging & compliance timelines to find it faster.

Parameters

To complete the configuration, select values for all parameters.

image-20260612-082040.png

Edit formula mode

If you click on Edit formula 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 status = [CHOSENSTATUS1, CHOSENSTATUS2, CHOSENSTATUS3];
let statuses = status.includes('Current Status') ? status.map((item)=> { if (item == 'Current Status'){return issue.status.name
}else{
return item;
}}): status;


let transitions = issue.changelogs?.flatMap((c) => c.items.filter((i) => i.field == "status").map((item) => ({
      from: item.fromString,
      to: item.toString,
      start: Number(c.created)
    }))
  ).sort((a, b) => Number(a.start) - Number(b.start));
  
  let initialCreationValue = {
  start: Number(issue.created),
  from: 'created',
  to: transitions[0]? transitions[0].from : issue.status.name
  };
  

let allTransitions = [initialCreationValue].concat(transitions).filter(item => statuses.includes(item.from) || statuses.includes(item.to));

let result =  allTransitions.reduce((acc, t) => {
  let prevStart = acc.prevStart;
  let prevStatus = acc.prevStatus;

  if (prevStart == null) {
    return {
      total: 0,
      prevStart: t.start,
      prevStatus: t.from
    }
  }
else{
return {
    total: statuses.includes(prevStatus) ? acc.total + (t.start - prevStart)  : acc.total,
    prevStart: t.start,
    prevStatus: t.to
  }
}
  
}, {
    total: 0,
    prevStart: 0,
    prevStatus: ""
  });

 statuses.includes(result.prevStatus)
    ? result.total + (Number(new Date()) - result.prevStart)
    : result.total;

[CHOSENSTATUS1, CHOSENSTATUS2 and CHOSENSTATUS3] is the list of the statuses chosen via the β€œStatus” parameter.

Display as

Duration

Formatting style

short

Details

This smart field expression calculates the total duration a work item has spent in a specific set of statuses. It accounts for the entire history of the work item, including the time spent in the current status up until the present moment.

1. What does the expression do?

The expression identifies a list of target statuses (selected by the user) and scans the work item's history (changelogs) to sum up every millisecond spent in those statuses. It effectively provides a "stopwatch" total for specific stages of a work item's lifecycle, such as "Total time in Progress" or "Total time in Review."

2. Step-by-step breakdown

  • Status Selection & Normalization:

    • The expression starts by taking the statuses you selected in the configuration (CHOSENSTATUS).

    • If "Current Status" was selected as a dynamic option, it maps that to the actual name of the work item's current status so the calculation knows exactly what to look for.

  • Extracting Transitions:

    • It accesses the Changelog (the history of changes) of the work item.

    • It filters these logs specifically for "status" changes and maps them into a list of transitions, noting the "from" status, the "to" status, and the exact timestamp (start) when the change occurred.

  • Establishing the Starting Point:

    • Since the first status change only records when a work item left its initial status, the expression manually adds an "initial creation" entry. This ensures the time spent in the very first status (from the moment the work item was created) is included.

  • Filtering and Sorting:

    • It combines the creation event with all subsequent transitions and sorts them chronologically.

    • It then filters this list to focus only on transitions that involve the statuses you are interested in.

  • The Accumulation Logic (Reduce):

    • The expression iterates through the timeline of transitions.

    • If the prevStatus (the status the work item was just in) matches one of your chosen statuses, it calculates the time difference between that transition and the previous one and adds it to the total.

  • Calculating Current Time:

    • Finally, it checks if the work item is currently in one of the selected statuses. If it is, it calculates the time from the last transition until "now" (new Date()) and adds that to the final sum.

3. Examples

  • Single Status: If you select only "In Progress," the field will show the total time the work item has been worked on, even if it was moved back to "To Do" and then back to "In Progress" multiple times.

  • Multiple Statuses: If you select "In Review" and "QA," the field will show the combined time the work item spent in both of those quality-control stages.

4. Real-life use cases

  • Bottleneck Identification: Use this to see which work items are spending an unusual amount of time in "Waiting for Approval" or "Blocked."

  • SLA Monitoring: Calculate the total "Active Time" (e.g., sum of "In Progress" and "In Development") to see if you are meeting internal performance targets, excluding time spent in "On Hold."

  • Process Efficiency: Compare the time spent in "Development" versus "Testing" across different projects to identify where resources might need to be reallocated.