Hey John, all,
I appreciate your initial posts and have torn these apart many times to do a lot of different things. One of the recent requests I had was similar to what Stefano and even Karan were asking above about "suspending" the SLA if the incident was put into some sort of a Hold status (i.e. Hold, Planned, Resolved, etc.)
There are a few ways to do this, but what I decided to do was the following: essentially, if a ticket has an SLA of 2 business days but it is put into hold for 1 day, then the time to complete (Due) becomes 3 days out from the creation. The amount of time the ticket is in Hold is added to the Due date.
One caveat is when a ticket is actually put into a Hold status, the Due date is not changed. So, any Notification Policies that are checking against the Due field need to also account only for incidents that are not in a Hold status. However, when it comes out of Hold and goes to another status (i.e. Resolved to Closed), then the Due date is adjusted accordingly.
What I did is added the following code to immediately after the "END OF USER-DEFINED SECTION". The only thing that needs to be modified is the part for your Hold Status IDs.
Code:
-----------------------------------------------------
-- Added to account for time in Hold Status
DECLARE @number int
DECLARE @version int
DECLARE @time int
DECLARE @totalhold int
DECLARE @totaldays int
DECLARE @totalmins int
SET @number = WORKITEM(workitem_number)
SET @version = (select workitem_version from workitem_current_view where workitem_number = @number)
SET @totalhold = 0
WHILE @version > 0
BEGIN
SET @version = @version - 1
SET @time = (SELECT DATEDIFF(mi,wid.workitem_modified_on,wip.workitem_modified_on)
FROM workitem_detail_view wid
JOIN
(SELECT workitem_number, workitem_version, workitem_modified_on
FROM workitem_detail_view
WHERE workitem_number = @number AND workitem_version = @version+1) wip ON wip.workitem_number=wid.workitem_number
WHERE wid.workitem_number = @number AND wid.workitem_version=@version
-- SET HOLD STATUS IDs
AND workitem_status_lookup_id IN (200,500))
SET @time = CASE
WHEN @time IS NULL THEN 0
ELSE @time
END
SET @totalhold = @totalhold + @time
END
set @sla = @sla + @totalhold
-----------------------------------------------------
This code will go backwards through all the items in the workitem_detail_view, sum the time that the incident was in hold and add it to the SLA.
Let me know how it works....
David