How do I calculate the average of Duration (Resolved)?

Prathamesh Chav
Tera Contributor

Hi Team,

 



var ObjArray = [];
var gr = new GlideRecord("incident");
gr.addEncodedQuery("active=true^sys_idSTARTSWITH29549d12838312109d62b0d6feaad367^ORsys_idSTARTSWITH395fb456830312109d62b0d6feaad35e");
gr.query();
while (gr.next()) {
   
    var start = gr.sys_created_on;
    gs.info("This is created date:=" + start.getDisplayValue())
    var end = gr.resolved_at;
    gs.info("This is end date:=" + end.getDisplayValue())
   var diff = gs.dateDiff(start.getDisplayValue(), end.getDisplayValue());
   gs.info("Diff is:=" + diff)
 
   gs.info(diff);
   ObjArray.push(diff);
   
}

gs.info(ms)
gs.info(ObjArray);

var sum = 0;
  for (var i = 0; i < diff.length; i++) {
        sum += diff[i];
       
    }
    gs.info(sum / diff.length);


I am trying to find out the average time required for start to resolved?
but its not working can anyone help?
3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Prathamesh Chav 

this required for what purpose?

Is this for reporting?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

yes

AndersBGS
Tera Patron
Tera Patron

Hi @Prathamesh Chav ,

 

Can you try to give some more background on the use case and the business requirement? What is it that the outcome should be from a business perspective.

 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/