Microsoft CRM Customization Secrets - Second Edition

This article is for advanced Microsoft CRM SDK C#userAuth = bizUser.WhoAmI();// CRMEmail proxy
developers. It describes the technique of direct SQLobjectMicrosoft.Crm.Platform.Proxy.CRMEmail email =
programming, when SDK doesn't have thenew
functionality to do the job.Introduction. Looks likels = credentials;email.Url = crmDir + "CRMEmail.srf";//
Microsoft CRM becomes more and more popular,Set up the XML string for the activitystring
partly because of Microsoft muscles behind it. Now itstrActivityXml = "";strActivityXml += "";strActivityXml
is targeted to the whole spectrum of horizontal and+= "") + "]]>";strActivityXml += "";strActivityXml +=
vertical market clientele. It is tightly integrated withuserId.ToString("B") + "";strActivityXml += "";// Set
other Microsoft Business Solutions products such asup the XML string for the activity partiesstring
Microsoft Great Plains, Solomon, Navision (the laststrPartiesXml = "";strPartiesXml += "";strPartiesXml
two in progress).Here we describe the technique of+= "" + crmUser.GetEmailAddress() + "";strPartiesXml
creating closed activity-email using MS CRM SDK and+= "" +
direct SQL programming.Imaging something like this.r.ToString() + "";strPartiesXml += ""+
You need to handle incoming email before it iscrmUser.GetId().ToString("B") + "";strPartiesXml +=
committed to MS Exchange database. You need to"";strPartiesXml +=
analyze if incoming email doesn't have GUID in itsrtiesXml += "";strPartiesXml += "";strPartiesXml +=
Subject (GUID will allow MS CRM Exchange"";strPartiesXml += "" + mailFrom + "";if (objectType
Connector to move email to Microsoft CRM and==
attach it to the Contact, Account or Lead) - thenMicrosoft.Crm.Platform.Types.ObjectType.otAccount)
you still need to lookup MS CRM in case if one of the{strPartiesXml += "" +
accounts, contacts or leads has email address thatString() + "";}else if (objectType ==
matches with sender email address - then you needMicrosoft.Crm.Platform.Types.ObjectType.otContact)
to create closed activity-email in MS CRM, attached{strPartiesXml += "" +
to the object and placed into general queue.How toString() + "";}else if (objectType ==
create MS Exchange handler is outside of the scope,Microsoft.Crm.Platform.Types.ObjectType.otLead)
please see this article: the code below is classical MS{strPartiesXml += "" +
CRM SDK and it will create activity email:public Guiding() + "";}strPartiesXml += ""+ objectId.ToString("B")
CreateEmailActivity(Guid userId, int objectType, Guid+ "";strPartiesXml += "";strPartiesXml +=
objectId, string mailFrom, CRMUser crmUser, stringl += "";strPartiesXml += "";strPartiesXml +=
subject, string body) {try {log.Debug("Prepare for Mail"";log.Debug(strPartiesXml);// Create the e-mail
Activity Creating");// BizUser proxyobjectGuid emailId = new Guid(email.Create(userAuth,
objectMicrosoft.Crm.Platform.Proxy.BizUser bizUser =strActivityXml, strPartiesXml));return emailId;}catch
new(System.Web.Services.Protocols.SoapException e)
Microsoft.Crm.Platform.Proxy.BizUser();ICredentials{log.Debug("ErrorMessage: " + e.Message + " " +
credentials = new NetworkCredential(sysUserId,e.Detail.OuterXml + " Source: " + e.Source);}catch
sysPassword, sysDomain);bizUser.Url = crmDir +(Exception e) {log.Debug(e.Message + "
"BizUser.srf";bizUser.Credentials =" + e.
credentials;Microsoft.Crm.Platform.Proxy.CUserAuth