Home Categories Submit Republish Tools Links Credits Contact
Popular Articles
 
     
 
 Categories
 
 
Submit your articles online!

Microsoft CRM Programming Secrets - Tips For Developers

By: Andrew Karasev

Published: August 1, 2006
Link To Article Link To Article  E-mail Article E-mail Article  Republish Article Republish Article
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.

Introduction. Looks like Microsoft CRM becomes more and more popular, partly because of Microsoft muscles behind it. Now it is targeted to the whole spectrum of horizontal and vertical market clientele. It is tightly integrated with other Microsoft Business Solutions products such as Microsoft Great Plains, Solomon, Navision (the last two in progress). Here we describe the technique of creating closed activity-email using MS CRM SDK and direct SQL programming.

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 {

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 += "" + CRMUser.GetEmailAddress() + "";

strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otSystemUser.ToString() + "";

strPartiesXml += ""+ CRMUser.GetId().ToString("B") + "";

strPartiesXml += "";

strPartiesXml += Microsoft.Crm.Platform.Types.ACTIVITY_PARTY_TYPE.ACTIVITY_PARTY_TO_RECIPIENT.ToString();

strPartiesXml += "";

strPartiesXml += "";

strPartiesXml += "";

strPartiesXml += "" + mailFrom + "";

if (objectType == Microsoft.Crm.Platform.Types.ObjectType.otAccount) {

strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otAccount.ToString() + "";

}

else if (objectType == Microsoft.Crm.Platform.Types.ObjectType.otContact) {

strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otContact.ToString() + "";

}

else if (objectType == Microsoft.Crm.Platform.Types.ObjectType.otLead) {

strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otLead.ToString() + "";

}

strPartiesXml += ""+ objectId.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 + "rn" + 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 activity closed:

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 + "rn" + e.StackTrace);

} }

Happy customizing! if you want us to do the job - give us a call 1-866-528-0577! help@albaspectrum.com

Andrew Karasev is Chief Technology Officer in Alba Spectrum Technologies – USA nationwide Microsoft CRM, Microsoft Great Plains customization company, based in Chicago, Boston, San Francisco, San Diego, Los Angeles, Houston, Atlanta, New York, and Miami and having locations in multiple states and internationally (www.albaspectrum.com/ ), he is Dexterity, SQL, VB/C#.Net, Crystal Reports and Microsoft CRM SDK developer.



Visitor Comments

Post Comment Post A Comment
What do you think about this article? Do you agree or disagree with it? Be the first to comment on this article, and share your thoughts with the world. No registration is required to post comments.

Article Icon Computer Programming - A Brief History
If a definition of a computer is that it is a piece of equipment that needs to follow various directions in order to carry out the tasks required of it, then the history of computers can be traced back to...
Article Icon Top 10 Elements Of Open Source Development
Open source development has undergone lot of changes to emerge as powerful in recent times. Today when software's are getting expensive consistently, open source techniques can eloquently help in making...
Article Icon The Usefulness Of Each IPhone Entertainment App
Apps with break through features like Audio/video playes, music players, and social media apps.
Article Icon Form Vs. Function? Which Is More Important In GUI Development?
During GUI training, students learn about graphical user interfaces. These are interfaces that allow users to interact with a computer in ways other than only typing and text.
Article Icon The Development Of IPhone Enterprise Apps
The Enterprise apps interact with the home server to get sensitive data of your customers.
Article Icon Alarm Clocks And Online Collaboration
Have you ever bought a piece of equipment that you thought would come in very handy only to leave it lying around for months because you could not figure out how to set it up? Or not set all the functions...
Article Icon IPhone Web Application Development
Since the creation of personal computers and the World Wide Web, technology has moved on to the creation of various computer and web applications that users can enjoy while using their personal computers or...
Article Icon Hire Android Developers
Google Android is a platform for professionals, offering a wide range of options and many opportunities for development of high quality Android applications. For the highly advanced and smart choices, the...
Article Icon Who Becomes An IPhone App Developer?
It's not a classic job title like fireman, president or teacher. Exactly who becomes an iPhone app developer, and what makes the job attractive to them? Read below to learn about the personality traits...
Article Icon Characteristics Of IPhone Application Developers
iPhone application developers share a common list of traits that serve them well in their chosen profession. Read below as you learn what makes these 'techies' so good at what they do, and then commission one

Article Icon Oracle E-Business Suite Development: New Technologies
We have already talked about the importance of Java Technologies at "Oracle E-Business Suite Customization: New Directions". Not only for Oracle Company itself, but also for the Oracle E-Business customers...
Article Icon Microsoft Dynamics GP: Auto Dealership Implementation
Microsoft Dynamics GP, or Microsoft Great Plains is very popular mid-market generic ERP. It can be used as ERP platform for multiple vertical markets. In this small article we'll describe typical auto...
Article Icon Microsoft CRM Integration With IBM Lotus Notes Domino - Machinery Dealership Example
IBM Lotus Notes with Domino email server is traditional document workflow management solution for large corporate business, where you need Audit trail on approval cycle and decision making. Microsoft Business
Article Icon ERP System Of The Future: Database, Business Logic And Interface
We will base our prognosis on our Microsoft Business Solutions ERP consulting practice: Microsoft Great Plains, Navision, Axapta, MS CRM. Also we've analyzed Oracle products: Oracle Financials, JD Edwards...
Article Icon Microsoft CRM Data Import FAQ
Microsoft CRM has built-in conversion tool, however you should probably first try third party conversion tool, such as Scribe. It is relatively expensive and has bunch of importing capabilities, that you...
Article Icon Microsoft CRM For Corporate Business - Working Offline
If your company has regional and worldwide operations, you might already realized that it is very hard to get decent Internet connection in your remote locations. In this small article we will try to give you
Article Icon Microsoft CRM USA Nationwide Remote Support
Remember old good days when your company probably had Great Plains Dynamics? If you are in San Francisco Bay Area - you had local Great Plains Software partner consulting company, who served you basically...
Article Icon Microsoft Great Plains: Customization Upgrade & Recovery - Visual Studio VB 6.0
Microsoft Great Plains, former Great Plains Software Dynamics, eEnterprise has very long, about 12 years customization & integration history. In earlier 1990th - the customization tool was mostly Great Plains
Article Icon Microsoft CRM Data Conversion FAQ
Microsoft Business Solutions CRM data conversion deserves FAQ type of article, where IT people could get initial directions. Even if it seems as a trivial task, we would suggest you to think about these...
Article Icon Lotus Notes Domino And Microsoft CRM Integration
Well, even if the combination might look very unusual, we see the coexistence of these two systems, especially in large corporations, non-profit organizations. Technically Lotus Notes Domino has parallel...


Print This Article Print This Article
Add To Favorites Add To Favorites
Cite This Article Cite This Article
 
 
Home | Categories | Submit | Republish | Tools | Links | Credits | Contact | Privacy Statement | Terms Of Use
Copyright © 2012 InfoServe Media, LLC (DBA PopularArticles.com). All rights reserved.