Calculate Real Time duration of ticket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2018 08:40 AM
We have an ask to generate a report on incidents and see how long they are open. The report needs to be able to pull incidents that have been open for 4 hours, 8 hours, 3 days, 5 days, etc. We use an incident state of "Pending" that pauses the SLA as well. So the total time I'm trying to get needs to basically ignore when the incident was in pending and continue the total time. I wrote a scheduled job to run and calculate the opened date and the current date, however, its not exactly real time. As well, the scheduled job, I would assume, is a performance impact. I need something that is real time and basically is the difference between when the ticket was opened and the current time, nothing stops this time unless the ticket is resolved. Is this possible to do? Any suggestions?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 08:11 AM
Look in to duration fields .
Here is an example on how we calculate something that we call onhold duration, in our case thsi Business rule kicks in when we go from Status Onhold.
It also adds to the duration value if the task has been set to On hold before.
(function executeRule(current, previous /*null when async*/) {
// SET on_hold_duration from current on_hold_at value
var on_hold_duration = calcWorkdaySchedule(current.u_on_hold_at,current.sys_updated_on); //Scriptinclude calcWorkdaySchedule
// SET saved (if any) u_on_hold_duration to miliceconds
var time_ms = current.u_on_hold_duration.dateNumericValue();
// Checks if incident have been set to hold before, if so then ads new duration to previouse value
if(time_ms>0){
// NOT my proudest lines of code,
current.u_on_hold_duration = on_hold_duration; // SETs new duration value to DB
var on_hold_duration_ms = current.u_on_hold_duration.dateNumericValue(); // Calculates new duration value to miliseconds
time_ms = time_ms + on_hold_duration_ms; // Calculates the total duration value (in miliseconds)
current.u_on_hold_duration.setDateNumericValue(time_ms); //SETs the new total duration to DB
} else{ // Incident never been in State on hold before
current.u_on_hold_duration = on_hold_duration;
}
})(current, previous);
Hope this helps you in some way.