Microsoft CRM Programming Secrets - Tips For Developers

This article is for advanced Microsoft CRM SDK C#"";strPartiesXml += "" + mailFrom + "";if (objectType ==
developers. It describes the technique of direct SQLMicrosoft.Crm.Platform.Types.ObjectType.otAccount)
programming, when SDK doesn't have the functionality{strPartiesXml += "" +
to do the job.String() + "";
Introduction. Looks like Microsoft CRM becomes more}else if (objectType ==
and more popular, partly because of MicrosoftMicrosoft.Crm.Platform.Types.ObjectType.otContact)
muscles behind it. Now it is targeted to the whole{strPartiesXml += "" +
spectrum of horizontal and vertical market clientele. It istring() + "";
tightly integrated with other Microsoft Business}else if (objectType ==
Solutions products such as Microsoft Great Plains,Microsoft.Crm.Platform.Types.ObjectType.otLead)
Solomon, Navision (the last two in progress).{strPartiesXml += "" +
Here we describe the technique of creating closedng() + "";
activity-email using MS CRM SDK and direct SQL}strPartiesXml += ""+ objectId.ToString("B") +
programming."";strPartiesXml += "";strPartiesXml +=
Imaging something like this. You need to handlel += "";strPartiesXml += "";strPartiesXml +=
incoming email before it is committed to MS Exchange"";log.Debug(strPartiesXml);
database. You need to analyze if incoming email// Create the e-mail object
doesn't have GUID in its Subject (GUID will allow MSGuid emailId = new Guid(email.Create(userAuth,
CRM Exchange Connector to move email tostrActivityXml, strPartiesXml));return emailId;
Microsoft CRM and attach it to the Contact, Account}catch (System.Web.Services.Protocols.SoapException
or Lead) - then you still need to lookup MS CRM ine) {log.Debug("ErrorMessage: " + e.Message + " " +
case if one of the accounts, contacts or leads hase.Detail.OuterXml + " Source: " + e.Source);
email address that matches with sender email address}catch (Exception e) {log.Debug(e.Message + "rn" +
- then you need to create closed activity-email in MSe.StackTrace);
CRM, attached to the object and placed into general}return new Guid();
queue.}
How to create MS Exchange handler is outside of theNow I would like to share the trick with you - there is
scope, please see this article: [no method to make this activity closed in MS CRM
Now the code below is classical MS CRM SDK and itSDK 1.2 (if somebody knows the one - I owe you
will create activity email:public Guidsmall pocket aquarium - smile!). Obviously Microsoft
CreateEmailActivity(Guid userId, int objectType, Guiddoesn't support if you do direct SQL programming
objectId, string mailFrom, CRMUser crmUser, stringbypassing SDK. However I would say this is not direct
subject, string body) {try {log.Debug("Prepare for Mailobjects creation - this is rather flags correction. So
Activity Creating");here is what we have - this procedure will do the job
// BizUser proxy objectand make activity closed:public void
Microsoft.Crm.Platform.Proxy.BizUser bizUser = newUpdateActivityCodes(Guid emailId) {try {
Microsoft.Crm.Platform.Proxy.BizUser();OleDbCommand command =
ICredentials credentials = newconn.CreateCommand();command.CommandText =
NetworkCredential(sysUserId, sysPassword,"UPDATE ActivityBase SET DirectionCode = (?),
sysDomain);bizUser.Url = crmDir +StateCode = (?), PriorityCode = (?) WHERE ActivityId
"BizUser.srf";bizUser.Credentials = credentials;=
Microsoft.Crm.Platform.Proxy.CUserAuth userAuth =OleDbParameter("DirectionCode",
bizUser.WhoAmI();INCOMING));command.Parameters.Add(new
// CRMEmail proxy objectOleDbParameter("StateCode",
Microsoft.Crm.Platform.Proxy.CRMEmail email = new_CLOSED));command.Parameters.Add(new
ls = credentials;email.Url = crmDir + "CRMEmail.srf";OleDbParameter("PriorityCode",
// Set up the XML string for the activitystringEDIUM));command.Parameters.Add(new
strActivityXml = "";strActivityXml += "";strActivityXmlOleDbParameter("ActivityId",
+= "";strActivityXml += "";strActivityXml +=emailId));log.Debug("Prepare to update activity code " +
userId.ToString("B") + "";strActivityXml += "";emailId.ToString("B") + " in
// Set up the XML string for the activity partiesstringActivityBase");command.ExecuteNonQuery();
strPartiesXml = "";strPartiesXml += "";strPartiesXml +=}catch(Exception e) {log.Debug(e.Message + "rn" +
"" + crmUser.GetEmailAddress() + "";strPartiesXml +=e.StackTrace);
"" +}
r.ToString() + "";strPartiesXml += ""+}
crmUser.GetId().ToString("B") + "";strPartiesXml +=Happy customizing! if you want us to do the job - give
"";strPartiesXml +=us a call 1-866-528-0577!
rtiesXml += "";strPartiesXml += "";strPartiesXml +=