Software Information |
Microsoft CRM Customization - Programming Closed Email Activity
Microsoft CRM is CRM answer from Microsoft and attempt to get market share from Siebel, Oracle and others traditional Client Relationship Management System vendors. Microsoft CRM uses all the spectrum of Microsoft recent technologies: .Net, MS Exchange, MS Outlook, MS SQL Server, Replication, Indexing, Active Directory, Windows 2000/2003 security model, C#, VB.Net, HTML, XML Web Service, XLTP, Javascript to name a few. Today's topic is Activity of email type programming - you usually deal with these customizations when you improve Microsoft Exchange CRM connector. How do you create closed activity - this is the main discussion topic. We'll use C#.Net coding One of the roles of our Exchange Event Handler/Sink is creation MS CRM Closed Activity in handling incoming and outgoing email messages. The interaction with Microsoft CRM uses two approached - using MS CRM SDK (handling inbound and outbound XML messages) and via direct access to MS CRM Database. Let's first look at the Closed Activity creation algorithm: 1. First we need to understand the entity we need to create activity for: Account, Lead or Contact. The selection should use specific criteria - in our case this is email address: if ((crmAccount = crmConnector.GetAccount(mailboxFrom)) != null) { } else if ((crmContact = crmConnector.GetContact(mailboxFrom)) != null) { } else if ((crmLead = crmConnector.GetLead(mailboxFrom)) != null) { } 2. Then we have to get GUID of MS CRM user, who owns this entity, C# code like this: crmUser = crmConnector.GetUser(crmAccount.GetOwnerId()); 3. Next step is closed Activity creation: emailId = crmConnector.CreateEmailActivity( crmUser.GetId(), Microsoft.Crm.Platform.Types.ObjectType.otAccount, crmAccount.GetId(), Microsoft.Crm.Platform.Types.ObjectType.otSystemUser, crmUser.GetId(), crmAccount.GetEmailAddress(), crmUser.GetEmailAddress(), sSubject, sBody); 4. The method to create closed activity: public Guid CreateEmailActivity(Guid userId, int fromObjectType, Guid fromObjectId, int toObjectType, Guid toObjectId, string mailFrom, string mailTo, string subject, string body) { try { log.Debug("Prepare for Mail Activity Creating"); // BizUser proxy object Microsoft.Crm.Platform.Proxy.BizUser bizUser = new Microsoft.Crm.Platform.Proxy.BizUser(); ICredentials credentials = new NetworkCredential(sysUserId, sysPassword, sysDomain); bizUser.Url = crmDir + "BizUser.srf"; bizUser.Credentials = credentials; Microsoft.Crm.Platform.Proxy.CUserAuth userAuth = bizUser.WhoAmI(); // CRMEmail proxy object Microsoft.Crm.Platform.Proxy.CRMEmail email = new Microsoft.Crm.Platform.Proxy.CRMEmail(); email.Credentials = credentials; email.Url = crmDir + "CRMEmail.srf"; // Set up the XML string for the activity string strActivityXml = ""; strActivityXml += ""; strActivityXml += "") + "]]>"; strActivityXml += ""; strActivityXml += userId.ToString("B") + ""; strActivityXml += ""; // Set up the XML string for the activity parties string strPartiesXml = ""; strPartiesXml += ""; strPartiesXml += "" + mailTo + ""; if (toObjectType == Microsoft.Crm.Platform.Types.ObjectType.otSystemUser) { strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otSystemUser.ToString() + ""; } else if (toObjectType == Microsoft.Crm.Platform.Types.ObjectType.otAccount) { strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otAccount.ToString() + ""; } else if (toObjectType == Microsoft.Crm.Platform.Types.ObjectType.otContact) { strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otContact.ToString() + ""; } else if (toObjectType == Microsoft.Crm.Platform.Types.ObjectType.otLead) { strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otLead.ToString() + ""; } strPartiesXml += ""+ toObjectId.ToString("B") + ""; strPartiesXml += ""; strPartiesXml += Microsoft.Crm.Platform.Types.ACTIVITY_PARTY_TYPE.ACTIVITY_PARTY_TO_RECIPIENT.ToString(); strPartiesXml += ""; strPartiesXml += ""; strPartiesXml += ""; strPartiesXml += "" + mailFrom + ""; if (fromObjectType == Microsoft.Crm.Platform.Types.ObjectType.otSystemUser) { strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otSystemUser.ToString() + ""; } else if (fromObjectType == Microsoft.Crm.Platform.Types.ObjectType.otAccount) { strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otAccount.ToString() + ""; } else if (fromObjectType == Microsoft.Crm.Platform.Types.ObjectType.otContact) { strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otContact.ToString() + ""; } else if (fromObjectType == Microsoft.Crm.Platform.Types.ObjectType.otLead) { strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otLead.ToString() + ""; } strPartiesXml += ""+ fromObjectId.ToString("B") + ""; strPartiesXml += ""; strPartiesXml += Microsoft.Crm.Platform.Types.ACTIVITY_PARTY_TYPE.ACTIVITY_PARTY_SENDER.ToString(); strPartiesXml += ""; strPartiesXml += ""; strPartiesXml += ""; log.Debug(strPartiesXml); // Create the e-mail object Guid emailId = new Guid(email.Create(userAuth, strActivityXml, strPartiesXml)); 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 + "" + e.StackTrace); } return new Guid(); } 5. To make the activity just created be shown correctly you need to setup it's flags according to MS CRM standards: public void UpdateActivityCodes(Guid emailId) { try { OleDbCommand command = conn.CreateCommand(); command.CommandText = "UPDATE ActivityBase SET DirectionCode = (?), StateCode = (?), PriorityCode = (?) WHERE ActivityId = (?)"; command.Prepare(); command.Parameters.Add(new OleDbParameter("DirectionCode", Microsoft.Crm.Platform.Types.EVENT_DIRECTION.ED_INCOMING)); command.Parameters.Add(new OleDbParameter("StateCode", Microsoft.Crm.Platform.Types.ACTIVITY_STATE.ACTS_CLOSED)); command.Parameters.Add(new OleDbParameter("PriorityCode", Microsoft.Crm.Platform.Types.PRIORITY_CODE.PC_MEDIUM)); command.Parameters.Add(new OleDbParameter("ActivityId", emailId)); log.Debug("Prepare to update activity code " + emailId.ToString("B") + " in ActivityBase"); command.ExecuteNonQuery(); } catch(Exception e) { log.Debug(e.Message + "" + e.StackTrace); } } public void UpdateActivityQueueCodes(Guid emailId, Guid queueId) { try { OleDbCommand command = conn.CreateCommand(); command.CommandText = "UPDATE QueueItemBase SET Priority = (?), State = (?), QueueId = (?) WHERE ObjectId = (?)"; command.Prepare(); command.Parameters.Add(new OleDbParameter("Priority", Microsoft.Crm.Platform.Types.PRIORITY_CODE.PC_MEDIUM)); command.Parameters.Add(new OleDbParameter("State", Microsoft.Crm.Platform.Types.ACTIVITY_STATE.ACTS_CLOSED)); command.Parameters.Add(new OleDbParameter("QueueId", queueId)); command.Parameters.Add(new OleDbParameter("ObjectId", emailId)); log.Debug("Prepare to update activity queue code " + emailId.ToString("B") + " in QueueItemBase"); command.ExecuteNonQuery(); } catch(Exception e) { log.Debug(e.Message + "" + e.StackTrace); } } Happy customizing, implementing and modifying! If you want us to do the job - give us a call 1-866-528-0577! help@albaspectrum.com About The Author Boris Makushkin is Lead Software Developer in Alba Spectrum Technologies - USA nationwide Microsoft CRM, Microsoft Great Plains customization company, based in Chicago, Boston, San Francisco, San Diego, Los Angeles, Houston, Dallas, Atlanta, Miami, Montreal, Toronto, Vancouver, Madrid, Moscow, Europe and internationally (www.albaspectrum.com), he is Microsoft CRM SDK, C#, VB.Net, SQL, Oracle, Unix developer. Boris can be reached: 1-866-528-0577 or borism@albaspectrum.com.
MORE RESOURCES: Unable to open RSS Feed $XMLfilename with error HTTP ERROR: 404, exiting |
RELATED ARTICLES
Does Microsoft have any real competition? Does Microsoft Have any Real Competition? Copyright (c) 2003 Gregory S. Diehl In a word, yes. eStore Advantage - Extending Microsoft eConnect for MBS Great Plains eStore Advantage allows front-office applications to communicate with back-office business environments. It has a built-in support for electronic payment processing, and serves as a core integration platform for Nodus Technologies front-to-back office connectivity suites including RMS and CRM Advantage. Microsoft Great Plains SOP: Sales Order Processing Microsoft Business Solutions Great Plains is marketed for mid-size companies as well as Navision (which has very good positions in Europe and emerging markets where it can be easily localized).Great Plains Sales Order Processing (SOP) module forms a third of the core Inventory and Order Processing part of Great Plains. Microsoft Great Plains - Microsoft RMS Integration - overview Microsoft Great Plains and Microsoft Retail Management System (Microsoft RMS) are originally developed by different software vendors, who had no idea that in the remote future (now) these two applications will be owned by Microsoft and will need to be tightly integrated. Current integration between the two is not an easy thing. Microsoft CRM Integration with Microsoft Retail Management System (RMS) - Overview Microsoft Client Relation Management system (Microsoft CRM) and Microsoft RMS are both Microsoft SQL Server based applications, however historically Microsoft was purchasing industry leading software applications, such as QuickSell which is now Microsoft RMS. So, RMS design fundamentals were minted a long time before Microsoft CRM. EDI: Electronic Document Interchange for Microsoft Great Plains - Overview for Software Developer/Pr Microsoft Great Plains - Microsoft Business Solutions accounting and ERP system, originally targeted to mid-size - now, with advancements and increasing reliability of its database - Microsoft SQL Server, Great Plains is attractive solution for large corporation. Big companies usually have purchasing and order processing automation via so-called Electronic Document Interchange or EDI. Linux Vs. Windows This article will not attempt to advocate the use of Linux over Windows or vice versa. I will try to present the differences and similarities between Linux and Windows in a fair manner. Removing Incoming Email in MS Exchange, C# Example The purpose of one of our projects was MS Exchange handler for processing incoming email.The basic source of knowledge was this article "Developing Managed Event Sinks/Hooks for Exchange Server Store using C#" by Logu Krishnan, published to the address http://www. Microsoft CRM Customization Secrets - Second Edition This article is for advanced Microsoft CRM SDK C# developers. It describes the technique of direct SQL programming, when SDK doesn't have the functionality to do the job. Collaboration Software: Index of Collaboration Software Technologies Collaboration SoftwareCollaboration Software, also known as group collaboration software or groupware, is software which allows cooperation on a business document between multiple parties on multiple computers. Collaboration software also allows the integration and merging of document changes and versions on a business document. Cisco Certification: Introduction To ISDN, Part V The major reason I recommend getting your hands on real Cisco equipment rather than a simulator is that real Cisco routers give you the chance to practice and learn show and debug commands.The knowledge you acquire from debugs is invaluable. Three Steps To Windows Safety Heaven Now there are Three Steps To HeavenJust listen and you will plainly seeHow virus and hackers attack and destroyYour precious internet-connected computer toyJust follow steps one, two and threeStep one - Run windows update automatically each dayStep Two - Always keep your antivirus running and updatedStep Three - Install and configure a firewallFaster VirusToday can many viruses find and infect a computer connecting to internet in less then 5 minutes, even if the computer connects to internet using a modem. And how much time will the 24/7 connected computer not give the bad guys?So leaving a computer without proper protection is not advisable. Microsoft Great Plains Implementation for Large Corporation - Overview for VP IT Microsoft Business Solutions Great Plains was historically designed to serve mid-market first and then with addition and acquisition of new modules - Great Plains Dynamics architects planned to enter into corporate market. When Microsoft SQL Server took its place as relatively reliable and stable database platform, Great Plains gained scalability. The Dreaded Paper Label - Should it be Used? While paper labeling CDs and DVDs may appear to be a cost effective solution for printing on your media, there are solid reasons why you should consider other options.1) Hand application of paper labels can be time consuming and frustrating. Navision Customization: C/SIDE, C/ODBC, C/FRONT, XBRL - Development Options Microsoft bought Navision, Denmark based software development company, along with Great Plains Software. Now Microsoft Business Solutions offers following ERP applications: Navision (former Navision Attain), Microsoft Great Plains (former Great Plains Dynamics/eEnterprise), Solomon, Axapta. History of Java The java programming language is becoming more and more popular each day. It is the language without which one cannot even hope to a land a job thesedays. Will Adobe Manage to Replace Industry Work Horse Quark Express by Giving Adobe InDesign for Free? Heard about the Quark "killer"?Adobe InDesign CS2. Will it really "kill" Quark? Adobe has been saying "it will" for the last six years or so, but it hasn't happened. Microsoft Great Plains Oil & Gas - Implementation & Customization Highlights Microsoft Great Plains serves the wide spectrum of horizontal markets. Great Plains could be considered as ERP platform, which you could expand with third party modules or advance with your own in-house custom functionality. Reporting for Microsoft Great Plains/Dynamics/eEnterprise: RW - ReportWriter - Tips for Developer Microsoft Business Solutions Great Plains is written in Great Plains Software programming tool: Great Plains Dexterity. Dexterity in turn was built with conception of graphical cross-platform transferability (in time - 1992 - mostly Mac and MS Windows). Software Automation Helps Increase your Bottom Line When you own a small business, time is money. And every time a task that should be automated is handled manually, it wastes your time and your business loses money. |
home | site map | contact us |