I want to track the time spent on support cases made by our clients in support portal. (According to service level agreement-SLA)
PS-Currently we record the time manually. But we want to track time automatically through a running clock according to the status change.
It should work as below,
Once the case is taken (take case) by one of our team members and the case is open, an internal clock, should run until we close the case. If we put the case to pending customer status, clock have to be stop from our end and once the client is responding to case once again, and status change to updated clock have to run again till we close the case.
Furthermore, when we change the status of case to pending customer and if they(client) do not reply in two days (48 hours), an automatic email has to be sent to the client reminding them to reply to the case. This may be done using a business event, but I have no idea, how to map the time to Business Event.
If anyone know the solution to this or use similar customization in yours, please do let me know.
Summary
Status of the case
Time
Open
Clock starts
Pending customer
Clock stops
Updated
Clock starts again
Closed
Clock stops
Best answer by aiwan
Hi @chameera71
Adding new fields for the start time, one for pause, one for unpause, one for closed, all invisible in the UI, and one field visible, total time.
Using a field updated handler for the status, and the newly added closed time field which could look something like this:
if(row.Status == "O")//Set the date/time of the record being opened { e.Cache.SetValueExt<ISORecord.startTime>(row, DateTime.Now); }
if (row.Status == "P")//Set the date/time of the record being pending { e.Cache.SetValueExt<ISORecord.pauseTime>(row, DateTime.Now); }
if(row.Status == "U")//Set the date/time of the record being updated { e.Cache.SetValueExt<ISORecord.unPauseTime>(row, DateTime.Now); }
if( row.Status == "C")//Set the date/time of the record being closed and fire FieldUpdated handler { e.Cache.SetValueExt<ISORecord.closedTime>(row, DateTime.Now); } }
protected virtual void _(Events.FieldUpdated<ISORecord, ISORecord.closedTime> e) { ISORecord row = e.Row; if (row == null) return; if (row.PauseTime != null) { TimeSpan time = row.PauseTime - row.StartTime;//Calculate the time of the record being open to paused. TimeSpan time2 = row.ClosedTime - row.UnPauseTime; //Calculate the time of the record being unpaused to closed.
TimeSpan totalTime = time + time2; //Calculate the time of the record being open to closed.
e.Cache.SetValueExt<ISORecord.totalTime>(row, totalTime.TotalMinutes); //Set the value in minutes. }
if(row.PauseTime == null) { TimeSpan time = row.ClosedTime - row.StartTime; //Calculate the time of the record being open to closed.
e.Cache.SetValueExt<ISORecord.totalTime>(row, time.TotalMinutes); //Set the value in minutes. }
if(row.Status == "O")//Set the date/time of the record being opened { e.Cache.SetValueExt<ISORecord.startTime>(row, DateTime.Now); }
if (row.Status == "P")//Set the date/time of the record being pending { e.Cache.SetValueExt<ISORecord.pauseTime>(row, DateTime.Now); }
if(row.Status == "U")//Set the date/time of the record being updated { e.Cache.SetValueExt<ISORecord.unPauseTime>(row, DateTime.Now); }
if( row.Status == "C")//Set the date/time of the record being closed and fire FieldUpdated handler { e.Cache.SetValueExt<ISORecord.closedTime>(row, DateTime.Now); } }
protected virtual void _(Events.FieldUpdated<ISORecord, ISORecord.closedTime> e) { ISORecord row = e.Row; if (row == null) return; if (row.PauseTime != null) { TimeSpan time = row.PauseTime - row.StartTime;//Calculate the time of the record being open to paused. TimeSpan time2 = row.ClosedTime - row.UnPauseTime; //Calculate the time of the record being unpaused to closed.
TimeSpan totalTime = time + time2; //Calculate the time of the record being open to closed.
e.Cache.SetValueExt<ISORecord.totalTime>(row, totalTime.TotalMinutes); //Set the value in minutes. }
if(row.PauseTime == null) { TimeSpan time = row.ClosedTime - row.StartTime; //Calculate the time of the record being open to closed.
e.Cache.SetValueExt<ISORecord.totalTime>(row, time.TotalMinutes); //Set the value in minutes. }