Microsoft Dynamics CRM 2015: How to Calculate a Work Timestamp Based on a Calendar

Enhanced Service Level Agreements (SLA’s) are one of the most helpful features that the latest version of Microsoft Dynamics CRM has to offer. This feature can calculate the amount of time spent on a specific case or even the amount of time a case was on hold.  However, SLAs cannot calculate the next work timestamp.

Consider the following scenario of escalating a critical case.

Challenge: You need to calculate the work timestamp that indicates when a critical case can be escalated based on a CSR’s calendar. If a critical case was created on Friday at 4:30pm and your CSR’s don’t work during the weekend, you need to add four hours to when the case is created and come up with a timestamp for when the case should be escalated. The timestamp should fall on a working day for a CSR. It could be on Monday or even Tuesday if it was a holiday weekend.

So how do you calculate a work timestamp based on a calendar in Microsoft Dynamics CRM 2015?

Solution:  We create a custom entity that takes a calendar GUID (string, as CRM does not allow lookups to Calendar entity – CSR calendar), start time (DateTime – case createdon/modifiedon), hours, minutes, and seconds as integers for the amount of time to add to the start time. On the creation of this entity, a plugin is triggered that does the calculation and stores the result in the same record in the work timestamp field. Employing a custom entity gives the benefit of calling create from JavaScript, custom code or even from inside any other plugin.

The following are screenshots of how the entity looks before and after.

Timestamp-Blog-Photo-1 Timestamp-Blog-Photo-2

Above you can see that based on a provided start time, the CSR calendar, and amount of time; the plugin calculates the work timestamp.

In this zip file, I have bundled this in an unmanaged CRM 2015 solution that you can import. Also available is a complete plugin code in case you would like to use the code separately.

If you’re using CRM as a platform for deploying line of business applications, make sure you’re getting the most from your investment by reading CRM Governance: What It Is, What It Isn’t, and How to Do It Right, an informative eBook written by governance experts.

By | 2018-04-03T18:45:23+00:00 December 15th, 2015|Sales & Service (CRM), Tech Tips|Comments Off on Microsoft Dynamics CRM 2015: How to Calculate a Work Timestamp Based on a Calendar
Alternative Text

Contributor: Ahmad Pirani

Ahmad Pirani Senior Consultant on the Delivery team. As the lead developer on CRM projects, is a highly skilled technical resource with deep development knowledge and CRM best practices.