Ho to calculate on hold time for an SLA attached to a task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2016 11:50 PM
Hi All,
I have a requirement where I need to calculate the on hold time for an SLA attached for a task. when a task is put in on hold state The SLA should not get paused and the SLA time should be calculated until the state is changed to some other state. Again if the SLA is put on hold from some other state then I need to display the Total time for which the SLA was in On hold state.
Please help me in solving this issue.
Immediate help is appreciated.
Regards,
Zabeeulla.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2016 12:01 AM
If you're not updating the Task SLA record, then do you even need to do anything with it at all? It sounds like you could do this by recording the time the State was changed to On Hold, and then when the State is changed again, calculate the time different between the on-hold time and the current time and display it to the user.
If I'm wrong, please provide more detail.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2016 12:25 AM
Hi Geoffrey,
Could you please help me with the script that how could I calculate the duration for which the ticket was on hold state, The time should contain the sum of all the times the ticket was on hold state.
Regards,
Zabeeulla.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2016 01:12 AM
You will need to create 2 new fields on the form and make them read-only:
- On hold since [u_on_hold_at] (Type: Date time) - For tracking when the State was change to On Hold
- On hold duration [u_on_hold_duration] (Type: Duration) - For tracking the total On Hold time
You will then need 2 Business Rules:
- When: before update
Condition: current.state.changesTo(3)
Script: current.u_on_hold_at = gs.nowDateTime(); - When: before update
Condition: current.state.changesFrom(3)Script:
if (current.u_on_hold_duration.nil()) {
// Calculate the duration from u_on_hold_at
current.u_on_hold_duration = gs.dateDiff(current.u_on_hold_at.getDisplayValue(), gs.nowDateTime(), false);
} else {
// Calculate the duration in seconds from u_on_hold_at, then add it to the existing total
var seconds = gs.dateDiff(current.u_on_hold_at.getDisplayValue(), gs.nowDateTime(), true);
var gdt = new GlideDateTime(current.u_on_hold_duration);
gdt.addSeconds(seconds);
current.u_on_hold_duration = gdt.getTime();
}
current.u_on_hold_at = '';

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2016 12:15 AM
Check out Metrics: Metrics
There is a default metric which would count the time per state for a given task record. This way you can easily report how long the task was 'on hold'. You might need than some database view to join the task_sla with the metric_instance table to get both numbers in one report. If the default metric dies not help, try creating your own metric having your custom business logic.