Quantcast

Microsoft CRM: Generic Web Development?

Get the WebProNews Newsletter:
[ Business]

Microsoft CRM is designed to be customizable. Also the conception of Microsoft CRM – it is a web-based application – sure it has the MS Outlook client, but this is auxiliary. So think about MS CRM as your web front. We do, however understand that programmers should be given examples on how to modify MS CRM. We are trying to cover this in this small article.

Imaging something like this. You need to handle incoming email before it is committed to MS Exchange database. You need to analyze if incoming email doesn’t have GUID in its Subject (GUID will allow MS CRM Exchange Connector to move email to Microsoft CRM and attach it to the Contact, Account or Lead) – then you still need to lookup MS CRM in case if one of the accounts, contacts or leads has email address that matches with sender email address – then you need to create closed activity-email in MS CRM, attached to the object and placed into general queue.

How to create MS Exchange handler is outside of the scope, please see this article: http://www.albaspectrum.com/Customizations_Whitepapers/Dexterity_SQL_VBA_Crystal/ExchangeHandlerExample.htm

Now the code below is classical MS CRM SDK and it will create activity email:

public Guid CreateEmailActivity(Guid userId, int objectType, Guid objectId, string mailFrom, CRMUser crmUser, string subject, string body) {
try {
&nbsp&nbsp log.Debug("Prepare for Mail Activity Creating");
&nbsp&nbsp // BizUser proxy object
&nbsp&nbsp Microsoft.Crm.Platform.Proxy.BizUser bizUser = new Microsoft.Crm.Platform.Proxy.BizUser();
&nbsp&nbsp ICredentials credentials = new NetworkCredential(sysUserId, sysPassword, sysDomain);
&nbsp&nbsp bizUser.Url = crmDir + "BizUser.srf";
&nbsp&nbsp bizUser.Credentials = credentials;
&nbsp&nbsp Microsoft.Crm.Platform.Proxy.CUserAuth userAuth = bizUser.WhoAmI();
&nbsp&nbsp // CRMEmail proxy object
&nbsp&nbsp Microsoft.Crm.Platform.Proxy.CRMEmail email = new Microsoft.Crm.Platform.Proxy.CRMEmail();
&nbsp&nbsp email.Credentials = credentials;
&nbsp&nbsp email.Url = crmDir + "CRMEmail.srf";
&nbsp&nbsp // Set up the XML string for the activity
&nbsp&nbsp string strActivityXml = "";
&nbsp&nbsp strActivityXml += "";
&nbsp&nbsp strActivityXml += "") + "]]>";
&nbsp&nbsp strActivityXml += "";
&nbsp&nbsp strActivityXml += userId.ToString("B") + "";
&nbsp&nbsp strActivityXml += "";
&nbsp&nbsp // Set up the XML string for the activity parties
&nbsp&nbsp string strPartiesXml = "";
&nbsp&nbsp strPartiesXml += "";
&nbsp&nbsp strPartiesXml += "" + crmUser.GetEmailAddress() + "";
&nbsp&nbsp strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otSystemUser.ToString() + "";
&nbsp&nbsp strPartiesXml += ""+ crmUser.GetId().ToString("B") + "";
&nbsp&nbsp strPartiesXml += "";
&nbsp&nbsp strPartiesXml += Microsoft.Crm.Platform.Types.ACTIVITY_PARTY_TYPE.ACTIVITY_PARTY_TO_RECIPIENT.ToString();
&nbsp&nbsp strPartiesXml += "";
&nbsp&nbsp strPartiesXml += "";
&nbsp&nbsp strPartiesXml += "";
&nbsp&nbsp strPartiesXml += "" + mailFrom + "";
&nbsp&nbsp if (objectType == Microsoft.Crm.Platform.Types.ObjectType.otAccount) {
&nbsp&nbsp strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otAccount.ToString() + "";
&nbsp&nbsp }
&nbsp&nbsp else if (objectType == Microsoft.Crm.Platform.Types.ObjectType.otContact) {
&nbsp&nbsp strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otContact.ToString() + "";
&nbsp&nbsp }
&nbsp&nbsp else if (objectType == Microsoft.Crm.Platform.Types.ObjectType.otLead) {
&nbsp&nbsp strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otLead.ToString() + "";
&nbsp&nbsp }
&nbsp&nbsp strPartiesXml += ""+ objectId.ToString("B") + "";
&nbsp&nbsp strPartiesXml += "";
&nbsp&nbsp strPartiesXml += Microsoft.Crm.Platform.Types.ACTIVITY_PARTY_TYPE.ACTIVITY_PARTY_SENDER.ToString();
&nbsp&nbsp strPartiesXml += "";
&nbsp&nbsp strPartiesXml += "";
&nbsp&nbsp strPartiesXml += "";
&nbsp&nbsp log.Debug(strPartiesXml);
&nbsp&nbsp // Create the e-mail object
&nbsp&nbsp Guid emailId = new Guid(email.Create(userAuth, strActivityXml, strPartiesXml));
&nbsp&nbsp return emailId;
}
catch (System.Web.Services.Protocols.SoapException e) {
log.Debug("ErrorMessage: " + e.Message + " " + e.Detail.OuterXml + " Source: " + e.Source);
}
catch (Exception e) {
log.Debug(e.Message + "\r\n" + e.StackTrace);
}
return new Guid();
}

Now I would like to share the trick with you – there is no method to make this activity closed in MS CRM SDK 1.2 (if somebody knows the one – I owe you small pocket aquarium – smile!). Obviously Microsoft doesn’t support if you do direct SQL programming bypassing SDK. However I would say this is not direct objects creation – this is rather flags correction. So here is what we have – this procedure will do the job and make the activity closed:

public void UpdateActivityCodes(Guid emailId) {
try {
&nbsp&nbsp OleDbCommand command = conn.CreateCommand();
&nbsp&nbsp command.CommandText = "UPDATE ActivityBase SET DirectionCode = (?), StateCode = (?), PriorityCode = (?) WHERE ActivityId = (?)";
&nbsp&nbsp command.Prepare();
&nbsp&nbsp command.Parameters.Add(new OleDbParameter("DirectionCode", Microsoft.Crm.Platform.Types.EVENT_DIRECTION.ED_INCOMING));
&nbsp&nbsp command.Parameters.Add(new OleDbParameter("StateCode", Microsoft.Crm.Platform.Types.ACTIVITY_STATE.ACTS_CLOSED));
&nbsp&nbsp command.Parameters.Add(new OleDbParameter("PriorityCode", Microsoft.Crm.Platform.Types.PRIORITY_CODE.PC_MEDIUM));
&nbsp&nbsp command.Parameters.Add(new OleDbParameter("ActivityId", emailId));
&nbsp&nbsp log.Debug("Prepare to update activity code " + emailId.ToString("B") + " in ActivityBase");
&nbsp&nbsp command.ExecuteNonQuery();
&nbsp }
&nbsp catch(Exception e) {
&nbsp&nbsp log.Debug(e.Message + "\r\n" + e.StackTrace);
&nbsp }
}

Andrew Karasev is Chief Technology Officer in Alba Spectrum Technologies USA nationwide Microsoft CRM, Microsoft Great Plains customization company, based in Chicago, California, Texas, New York, Georgia and Florida and having locations in multiple states and internationally (www.albaspectrum.com), he is Dexterity, SQL, C#.Net, Crystal Reports and Microsoft CRM SDK developer.

Microsoft CRM: Generic Web Development?
Comments Off
About Andrew Karasev
Andrew Karasev is Chief Technology Officer in Alba Spectrum Technologies USA nationwide Microsoft CRM, Microsoft Great Plains customization company, based in Chicago, California, Texas, New York, Georgia and Florida and having locations in multiple states and internationally (www.albaspectrum.com), he is Dexterity, SQL, C#.Net, Crystal Reports and Microsoft CRM SDK developer. WebProNews Writer
Top Rated White Papers and Resources

Comments are closed.