SLAs in Microsoft CRM – A simple Demo

March 23, 2009 at 3:43 pm | Posted in Microsoft Dynamcis CRM | Leave a comment

A while ago I was asked to demonstrate Service Level Agreements (SLAs) within Microsoft CRM by my collegues.

The requirement:

  • Customer buys software and chooses appropriate SLA
  • Each SLA will have different response times
  • Each SLA will have different priority levels (High, Medium, Low)

Example SLA:

Priority Level

Response Time

Temporary Solution

Remedy

1 (Complete Failure)

2 hours

4 hours

16 hours

2 (High)

4 hours

8 hours

7 days

3 (Medium)

1 day

2 days

30 days

4 (Low)

5 days

30 days

60 days

 

Solution:

  • New custom entities were created to represent the ‘SLA administration module’.
    • SLA – Gold, Silver, Bronze
    • SLA Times – Represents Priority Levels, Response Time, Temp Solution and Remedy

1459268-973019-thumbnail.jpg 1459268-973021-thumbnail.jpg

  • The new “SLA” entity is related to a the MSCRM Contract entity.

1459268-973024-thumbnail.jpg

  • A contract (with an associated SLA) is recorded against the Account record

1459268-973028-thumbnail.jpg

  • The Case entity is configured with the new “Priority Level” picklist and “Response/Temp Solution/Remedy” date fields

1459268-973031-thumbnail.jpg

  • A pre-create callout on the Case entity will ‘lookup’ SLA details for chosen contract and populate date fields when Case is saved

1459268-973033-thumbnail.jpg

The Callout:

using System;
using System.Data;
using System.Text;
using System.Xml;
using System.IO;
using Microsoft.Crm.Callout;
namespace MyNamespace.MyCallouts
{
public class MyCallout : CrmCalloutBase
{
public static void SetProperty(ref XmlDocument entityXmlDoc, string propertyName, string type, string stringValue, string attributes)
{
foreach (XmlElement element in entityXmlDoc.GetElementsByTagName(“Property”))
{
if (element.Attributes.GetNamedItem(“Name”).Value == propertyName)
{
element.FirstChild.InnerText = stringValue;
return;
}
}
XmlNode propertiesNode = entityXmlDoc.GetElementsByTagName(“Properties”)[0];
XmlNode nodeNewProperty = propertiesNode.LastChild.Clone();
nodeNewProperty.Attributes[“xsi:type”].Value = type;
nodeNewProperty.Attributes[“Name”].Value = propertyName;
nodeNewProperty.InnerXml = string.Format(“<Value>{0}</Value>”, stringValue);
propertiesNode.InsertAfter(nodeNewProperty, propertiesNode.LastChild);
}
//Use the appropriate method, based on the event that you are programming against
public override PreCalloutReturnValue PreCreate(CalloutUserContext userContext, CalloutEntityContext entityContext,
ref string entityXml, ref string errorMessage)
{
//Add your code here
string debug = “”;
debug = entityXml;
try
{
// grab the contract id passed in from the case
string contractid = “”;
string priority = “”;
XmlDocument xd = new XmlDocument();
xd.LoadXml(entityXml);
foreach (XmlElement element in xd.GetElementsByTagName(“Property”))
{
if (element.Attributes.GetNamedItem(“Name”).Value == “contractid”)
{
contractid = element.InnerText;
}
if (element.Attributes.GetNamedItem(“Name”).Value == “new_prioritylevel”)
{
priority = element.InnerText;
}
}
debug = debug + ” Contract: ” + contractid;
debug = debug + ” Priority: ” + priority;
// get the sla from the contract
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
ColumnSet cols = new ColumnSet();
cols.Attributes = new string[] { “new_servicelevelid” };
TargetRetrieveContract target = new TargetRetrieveContract();
target.EntityId = new Guid(contractid);
RetrieveRequest retrieve = new RetrieveRequest();
retrieve.Target = target;
retrieve.ColumnSet = cols;
RetrieveResponse retrieved = (RetrieveResponse)service.Execute(retrieve);
contract contract = new contract();
contract = (contract)retrieved.BusinessEntity;
debug = debug + ” SLA: ” + contract.new_servicelevelid.Value;
ColumnSet colsTimes = new ColumnSet();
colsTimes.Attributes = new string[] { “new_remedy”, “new_responsetime”, “new_temporarysolution”, “new_slatimeid” };
ConditionExpression con1 = new ConditionExpression();
con1.AttributeName = “new_slaid”;
con1.Operator = ConditionOperator.Equal;
con1.Values = new string[] { contract.new_servicelevelid.Value.ToString() };
ConditionExpression con2 = new ConditionExpression();
con2.AttributeName = “new_prioritylevel”;
con2.Operator = ConditionOperator.Equal;
con2.Values = new string[] { priority };
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] { con1, con2 };
QueryExpression query = new QueryExpression();
query.EntityName = EntityName.new_slatime.ToString();
query.ColumnSet = colsTimes;
query.Criteria = filter;
BusinessEntityCollection times = service.RetrieveMultiple(query);
debug = debug + ” Times Retrieved: ” + times.BusinessEntities.Length.ToString();
string response = “”, temp = “”, remedy = “”;
foreach (Object o in times.BusinessEntities)
{
new_slatime time = new new_slatime();
time = (new_slatime)o;
debug = debug + ” SLATIME: ” + time.new_slatimeid.Value;
response = time.new_responsetime.Value.ToString();
temp = time.new_temporarysolution.Value.ToString();
remedy = time.new_remedy.Value.ToString();
}
// update case sla / due date
SetProperty(ref xd, “new_responsetime”, “CrmNumberProperty”, response, “”);
SetProperty(ref xd, “new_temporarysolution”, “CrmNumberProperty”, temp, “”);
SetProperty(ref xd, “new_remedy”, “CrmNumberProperty”, remedy, “”);
SetProperty(ref xd, “followupby”, “CrmDateTime”, “2007-04-27T00:00:00”, “”);
entityXml = xd.OuterXml;
debug = debug + ” XML: ” + xd.InnerXml.ToString();
WriteToFile(debug);
}
catch (SystemException e)
{
WriteToFile(debug + ” ” + e.Message);
}
return PreCalloutReturnValue.Continue;
}
}
}
Advertisements

Leave a Comment »

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: