The CreatorCon Call for Content is officially open! Get started here.

metric is not ending when ticket gets closed

anshul_jain25
Kilo Guru

I have created a metric which store duration how much time a assignment group is taking. but this metic should end when ticket is closed

find_real_file.png

calculation should complete and metric should provide duration when ticket is closed or inactive

1 ACCEPTED SOLUTION

Hi Alikutty,



below is the code which i found from communities which is running for me,



if (current.state == 6) {     //change according to your closed state


  answer = false;


  mi.endDuration();


closeDurations(mi.current);


}




function closeDurations(current) {


  var gr = new GlideRecord('metric_instance');


  gr.addQuery('id', current.sys_id);


gr.addQuery('calculation_complete', false);


gr.addQuery('definition.type', 'field_value_duration');


gr.addQuery('definition', '39d43745c0a808ae0062603b77018b90'); //mark your metric definition sysid


  gr.query();


  while (gr.next()) {


  var definition = new GlideRecord('metric_definition');


  definition.get(gr.definition);


  var mi = new MetricInstance(definition, current);


  mi.endDuration();


  }


}


View solution in original post

38 REPLIES 38

Hi Vikrami,

Attached is the HR Metric that works for me, hopefully this helps you with your issue.

Cheers

Carl.find_real_file.png

Thank you @Carl Fransen for your response.

I am having same script as yours, but its not closing when case is closed. Only difference is, my metric is running on Assignment group field value & yours is on Active. Do I need to change anything in the above script to accommodate the difference. Appreciate your advice!

Hi @vikrami ,

 

The intention of the 'active' metric is that it closes off all the other metrics against the records.  Without this metric, on the active field, when the Case is closed the other metrics will not also close off properly.

You will need t either update your metric to use the 'active' field, or if you need to continue to measure your 'assignment group' metric, create a new metric that is on the 'Active' field.

My HR Metric weren't closing off properly either until I created the HR metric on 'Active'.

Hope this helps.

Cheers

Carl.

Ok, so I need to create two metrics - as I want to measure total time Assigned to has the case - one for Assigned to & one for Active.

But then How can I combine these two to create one report?

Hi vikrami,

The Metric on 'Active' is only there for closing off the other metrics - you wouldn't need to combine this with your other metric on Assignment Group.  The Assignment Group will be able to provide you the report you need by itself, it 's just that having the 'Active' one actually stops ad closes metric correctly when the ticket is closed.  So there's no need to combine these to make one report.

Additionally have you thought about the time measurement for these reports - do you want Business Time, or Total time?  By default the metrics all use Total Time, so a 24x7 clock vs using a Business Time clock which could be 8am to 5pm only.  Something additional to think about once you get the above working.