- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 10:48 PM
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
Thank you,
Siva
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 11:31 PM - edited 08-17-2023 12:11 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 11:01 PM
Try this
var totalDurationInMinutes = 0;
var outages = new GlideRecord('cmdb_ci_outage');
outages.addEncodedQuery('cmdb_ci=c44f4c5447cc5114a6954d68436d433a');
outages.query();
while (outages.next()) {
var duration = parseFloat(outages.getValue('duration'));
if (!isNaN(duration)) {
totalDurationInMinutes += duration;
}
}
var totalDurationInSeconds = totalDurationInMinutes * 60;
gs.info('Total Duration in Minutes: ' + totalDurationInMinutes);
gs.info('Total Duration in Seconds: ' + totalDurationInSeconds);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 11:27 PM
Hi Harish,
Thank you for quick response,
I am using this script, But it showing wrong calculation.
And tried different ddEncodedQuery.Its showing same value.
for reference I have attached screenshot
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 11:31 PM - edited 08-17-2023 12:11 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 12:29 AM
It's working,
Thank you so much for your help.