| This article is for advanced Microsoft CRM SDK C# | | | | "";strPartiesXml += "" + mailFrom + "";if (objectType == |
| developers. It describes the technique of direct SQL | | | | Microsoft.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 Microsoft | | | | Microsoft.Crm.Platform.Types.ObjectType.otContact) |
| muscles behind it. Now it is targeted to the whole | | | | {strPartiesXml += "" + |
| spectrum of horizontal and vertical market clientele. It is | | | | tring() + ""; |
| 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 closed | | | | ng() + ""; |
| activity-email using MS CRM SDK and direct SQL | | | | }strPartiesXml += ""+ objectId.ToString("B") + |
| programming. | | | | "";strPartiesXml += "";strPartiesXml += |
| Imaging something like this. You need to handle | | | | l += "";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 MS | | | | Guid emailId = new Guid(email.Create(userAuth, |
| CRM Exchange Connector to move email to | | | | strActivityXml, 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 in | | | | e) {log.Debug("ErrorMessage: " + e.Message + " " + |
| case if one of the accounts, contacts or leads has | | | | e.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 MS | | | | e.StackTrace); |
| CRM, attached to the object and placed into general | | | | }return new Guid(); |
| queue. | | | | } |
| How to create MS Exchange handler is outside of the | | | | Now 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 it | | | | SDK 1.2 (if somebody knows the one - I owe you |
| will create activity email:public Guid | | | | small pocket aquarium - smile!). Obviously Microsoft |
| CreateEmailActivity(Guid userId, int objectType, Guid | | | | doesn't support if you do direct SQL programming |
| objectId, string mailFrom, CRMUser crmUser, string | | | | bypassing SDK. However I would say this is not direct |
| subject, string body) {try {log.Debug("Prepare for Mail | | | | objects creation - this is rather flags correction. So |
| Activity Creating"); | | | | here is what we have - this procedure will do the job |
| // BizUser proxy object | | | | and make activity closed:public void |
| Microsoft.Crm.Platform.Proxy.BizUser bizUser = new | | | | UpdateActivityCodes(Guid emailId) {try { |
| Microsoft.Crm.Platform.Proxy.BizUser(); | | | | OleDbCommand command = |
| ICredentials credentials = new | | | | conn.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 object | | | | OleDbParameter("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 activitystring | | | | EDIUM));command.Parameters.Add(new |
| strActivityXml = "";strActivityXml += "";strActivityXml | | | | OleDbParameter("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 partiesstring | | | | ActivityBase");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 += | | | | |