Metric of time spend in a specific state

Inga Karl
Giga Contributor

Hi There, 

 

is there a possibility to measure the time a tickets spends in a specific state? I would like to have an average time tickets of a specific service are on hold or work in progress. How would I do this? 

 

Best

Inga

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hello @Inga Karl ,

Yes, this is possible with Metrics of Type script calculation. PFB screen shot - 

find_real_file.png

Code - 

var s = current.incident_state;
if (s == 2) // if state is In Progress
  createMetric();

function createMetric() {
  var mi = new MetricInstance(definition, current);
  if (mi.metricExists()) 
    return; 

  var gr = mi.getNewRecord();
  gr.value = current.incident_state.getDisplayValue(); 
  gr.start = current.sys_created_on;
  gr.end = current.sys_updated_on;
  gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
  gr.calculation_complete = true;
  gr.insert();
}

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact. 

Thanks
Akshay Kangankar

 

View solution in original post

3 REPLIES 3

Community Alums
Not applicable

Hello @Inga Karl ,

Yes, this is possible with Metrics of Type script calculation. PFB screen shot - 

find_real_file.png

Code - 

var s = current.incident_state;
if (s == 2) // if state is In Progress
  createMetric();

function createMetric() {
  var mi = new MetricInstance(definition, current);
  if (mi.metricExists()) 
    return; 

  var gr = mi.getNewRecord();
  gr.value = current.incident_state.getDisplayValue(); 
  gr.start = current.sys_created_on;
  gr.end = current.sys_updated_on;
  gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
  gr.calculation_complete = true;
  gr.insert();
}

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact. 

Thanks
Akshay Kangankar

 

Community Alums
Not applicable

Hello @Inga Karl ,

Glad my answered is helped you, is your requirement is completed with my answer. If Yes then please mark my answer Correct as well. It will use for other community members.

If not let us know your issue so we can help you.


Thanks
Akshay Kangankar 

Diane Zawada
Tera Contributor

Akshay - I'm wondering if I can use this to calculate the length of time a RITM is open. We have RITMs with more than one task and we are trying to understand the length of time the entire RITM is open and secondly to understand how long the SCTasks associated with a RITM are open.  We are currently on UTAH. Di