unable to populate duration properly
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 12:39 PM
i am trying to get average of an sla duration and trying to populate as text but it is giving me improperformat and imoroper values
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 01:04 PM
Hi @chaithanya03091 Please try below updated script. I tried this in PDI and working as expected. Update query as per your need.
var durationGR = new GlideRecord('task_sla');
durationGR.addEncodedQuery('task=ef43c6d40a0a0b5700c77f9bf387afe3');
durationGR.query();
var totalDurationMillis = 0;
var recordCount = 0;
while (durationGR.next()) {
var durationStr = durationGR.getValue('business_duration');
if (durationStr) {
var durationObj = new GlideDuration(durationStr);
totalDurationMillis += durationObj.getNumericValue();
recordCount++;
}
}
if (recordCount > 0) {
var averageDurationMillis = totalDurationMillis / recordCount;
var averageDuration = new GlideDuration(averageDurationMillis);
var days = Math.floor(averageDuration.getNumericValue() / (1000 * 60 * 60 * 24));
var hours = Math.floor((averageDuration.getNumericValue() % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((averageDuration.getNumericValue() % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((averageDuration.getNumericValue() % (1000 * 60)) / 1000);
var formattedDuration = days + " days, " + hours + " hours, " + minutes + " minutes, " + seconds + " seconds";
gs.info("Average SLA Duration: " + formattedDuration);
} else {
gs.info("No SLA records found for the given query.");
}
Please mark my answer correct and helpful if this works for you.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 01:11 PM
no it is giving me the following answer
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 01:18 PM
@chaithanya03091 try this
var list = new GlideRecord("task_sla");
list.addEncodedQuery("task=ef43c6d40a0a0b5700c77f9bf387afe3");
list.setLimit(10);
list.query();
while (list.next()){
gs.info(list.business_duration.getDisplayValue());
}