Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Yes, even I dont think this will work, because the field we are using is Assignment group, and we are checking for state change in the script.

A business rule may help to set this value.

Thanks,

Krishna

 

 

@Krishna, Can you please help how can this done with BR?

Carl Fransen1
Kilo Sage

Hi - this is probably a bit late but thought it couldn't hurt to reply.  I created a bunch of HR Metrics and these were also not closing off.  However I just copied the OOTB Incident one, which runs at an order of 10, so before everything else, and closes all metrics on inactive tables...

 

Screenshot of OOTB metric below.

 

find_real_file.png

Hope this helps someone!

 

Cheers

Carl.

Thank you so much!!

@Carl Fransen

This script work when I am adding it to "Incident" table related Metrics. But not working for HR Case related metrics. Can you please help.