Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Metrics definitions on assigned_to field using script calculation

somadileep840
Giga Contributor

Hi All,
I am new to metrics and in learning stage , require some help with Script. Here i want to create metric definition on assigned_to field ,which can be done using TYPE:Field value duration .But here i want to achieve same results using
TYPE : script calculation . Some one pls share me the Draft code.

Thanks in Advance
Soma

4 REPLIES 4

Bert_c1
Kilo Patron

Look at the OOB Metric Definition named "Open" (MTRC0000007) in my instance.

 

// script can set answer to false to terminate processing of the metric
// mi - MonitorInstance
// answer
if (!current.active) {
  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.query();
    while (gr.next()) {
       var definition = new GlideRecord('metric_definition');
       definition.get(gr.definition);
       var mi = new MetricInstance(definition, current);
       mi.endDuration();
    }
}
  

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @somadileep840 

 

Did you checkOOTB metrics

DrAtulGLNG_0-1748528482100.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Dr Atul G- LNG ,
I want to get this with Type: Script calculation

Hi @somadileep840 

If you can achieve this without scripting, is there any specific reason you’re looking to use scripts?

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************