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

Alikutty A
Tera Sage

Hi,



Can you show a screenshot of your metric definition?



Thank You


Please Hit Like, Helpful or Correct depending on the impact of response


Sure,PFB



find_real_file.png


Is this a scoped table? If Yes, on your HR employee care table configuration, please change the application access setting to allow can update and see if it works out.



find_real_file.png



http://wiki.servicenow.com/index.php?title=Application_Access_Settings#Set_Runtime_Access_to_Applica...



Thank You


Please Hit Like, Helpful or Correct depending on the impact of response


allow update is checked, metrics is also working, i want to know that when any ticket whether it is incident or hr case, what configuration needs to be done so that metrics should stop and calculate duration. in incident also i have checked metrics are not stoping for closed incident