Calculate the total duration hours from different record.

Siva82
Tera Expert

Hi All,

 

 

I am try to calculate the total hours of duration in background. I wrote script in background script. It getting all duration values from different records. But I need sum of the total duration and convert in to Mints or seconds.

Can you please help me on that.

 

I am using below script, and for reference I have attached screenshot

//var dur = [];
//var sum_dur;
var outages = new GlideRecord('cmdb_ci_outage');
//outages.addEncodedQuery('sys_created_onONLast 12 months@javascript:gs.beginningOfLast12Months()@javascript:gs.endOfLast12Months()^cmdb_ci=' + current.dimension.configuration_item);
outages.addEncodedQuery('cmdb_ci=c44f4c5447cc5114a6954d68436d433a');
outages.query();
while(outages.next()){
    //dur = dur.push(outages.getValue('duration'));
   var dur = outages.getDisplayValue('duration');      
sum_dur = dur;
gs.info(dur);
}
Siva82_0-1692251259479.png

Thank you,

Siva

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

hELLO @Siva82 ,

YOU CAN USE THIS SCRIPT 

 

var dur=0;
var gr = new GlideRecord('cmdb_ci_outage');
gr.query();
while(gr.next())
{
dur=dur+gr.duration.dateNumericValue()/(60*60*1000);
  //dur =dur+(gr.duration.dateNumericValue()/ (60*60*1000) );

}
gs.info(dur);



 

 

This gave me the added duration value in hours

 

Hope this helps 

Mark my answer correct if this helps you 

Thanks

View solution in original post

8 REPLIES 8

Samaksh Wani
Giga Sage
Giga Sage

Hello @Siva82 

 

sum_dur+=dur;

 

write this.

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

Hi Wani,

Thank you for quick response,

I tried this sum_dur+=dur;, Its not working

Hello @Siva82 

 

the field you are fetching is string type or date type .

It's Duration type

Siva82_0-1692252061072.png