Microsoft CRM Programming Secrets ? Tips For Developers

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/ExchangeHandlerEx ample.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();

strPa rtiesXml += "";

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();

strPartiesX ml += "";

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.

Microsoft CRM Programming Secrets ? Tips For Developers

This article is for advanced Microsoft CRM SDK C# developers. It describes the technique of... Read More

Vlans

In order to implement VLANs in a network environment, you'll need a Layer 2 switch... Read More

3 Reasons Why Medical Billing Software is Leading the Way

Since technology changes so quickly, it is hard to begin by saying "in the old... Read More

Corel WordPerfect 7 Macro Programming Example

Case study: A secretary using Corel WordPerfect 7 is often required to carry out calculations... Read More

Assertion in Java

Assertion facility is added in J2SE 1.4. In order to support this facility J2SE 1.4... Read More

What is a Document Manager without Version History?

Document Manager and Version HistoryIn previous articles I have discussed the usefulness of a document... Read More

Your Computer May Be Infected, Heres How To Check (NOT about virus)

NOTE: Please take time to read on - it may be vital for your PC's... Read More

Freight Forwarding ERP: Microsoft Business Solutions Great Plains customization & setup ? overview

Microsoft Great Plains may be recommended for international freight forwarding / transportation company. Great Plains... Read More

The Dreaded Paper Label - Should it be Used?

While paper labeling CDs and DVDs may appear to be a cost effective solution for... Read More

Anti-Spyware Protection ? Holes in the Shining Armor

Looking at all the ads which promise to get rid of all spy programs, one... Read More

Microsoft Business Solutions Customization Options - Overview for Programmer

Several years ago Microsoft purchased Great Plains Software, then Navision (Denmark based software development company).... Read More

OEComplete ? A Personal Information Manager

OEComplete is a utility for managing the personal information of the user. It is designed... Read More

Popular Fleet Maintenance Programs

Some companies that are in need of fleet management may choose to utilize the services... Read More

C++ Tutorial 1, Introduction to C++

Introduction to C++Why Learn C++?C++ may at first seem like a boring, confusing programming language... Read More

Microsoft Axapta, Navision or Great Plains: ERP Selection for Large Corporation

If you would like to pick something from Microsoft, or its ERP subdivision ? Microsoft... Read More

Quick Summary of Basic and Common Linux Commands

There are many commands that are used in linux on a daily basis, ones that... Read More

New Web-Based HR Tool is Max From NAS, Hannibal, and InfoLink

Three highly respected names in Human Resources have joined forces to provide companies with a... Read More

Great Plains Customization ? Programming Auto-apply in Accounts Receivable

Microsoft Great Plains is one of three Microsoft Business Solutions mid-market ERP products: Great Plains,... Read More

Microsoft Great Plains Project Accounting ? Overview For IT Director/Controller

Microsoft Business Solutions is now in process of creating so called Microsoft Suites: Microsoft Financials,... Read More

Microsoft Great Plains PM: Payables Management

Microsoft Business Solutions Great Plains is marketed for mid-size companies as well as Navision (which... Read More

Algebra Help Software

Need help making sense of algebra? Have algebra lectures in your classroom left you scratching... Read More

Exactly What Does FTP Stand for and What Can it do for Me?

FTP stands for "file transfer protocol". FTP is basically a way of sending files over... Read More

C++ Function Templates

C++ Function templates are those functions which can handle different data types without separate code... Read More

Professional Software Icons For Your Standalone Application

User interfaces and accessibility are some of the most important aspect of an application. It... Read More

Google Brings the Earth to Your Desktop

Google Inc. has launched a new software package that allows you to see satellite images... Read More

Software Process Improvement -A Successful Journey

Background: For many organizations like ours, the interim target of achieving ISO 9001 or CMM... Read More

Chinese Input - Step by Step Instruction on How to Input Chinese Characters in English Windows XP

Enabling Chinese input is quick and easy, there are only a few steps you need... Read More

eConnect: eCommerce Development for Microsoft Great Plains

Microsoft Business Solutions Great Plains has several options to enable web ordering. Traditionally Great Plains... Read More

String in Java

Handling character strings in Java is supported through two final classes: String and StringBuffer. The... Read More

.Net Charts and Graphs Interact with Businesses and Customers

Bar charts, bar graphs, and any other chart or graph used in financial statements, inventory... Read More

Windows Screensavers Explained

In this article you will find some background information about screensavers and their history. You... Read More

Free Software: How Not To Get More Than You Bargained For!

I completed an experiment recently. I wanted to find out exactly what software I could... Read More

The Tools and Features of Adobe Photoshop

Adobe Photoshop is one of the world's leading graphics editing programs, developed by Adobe Systems.... Read More

Keeping Track

One of the things we can be as certain of as death and taxes is... Read More

Think Of This

Think of this, first we had the HAM Radio, then the bbs and now the... Read More

Dashboard Widgets for Windows

For a windows user like me, just can watch with envy the new eye candy... Read More

Removing Incoming Email in MS Exchange, C# Example

The purpose of one of our projects was MS Exchange handler for processing incoming email.The... Read More

What Stands Behind The Software Description?

With thousands of web pages added to the Net every day, it's getting more and... Read More

Microsoft Great Plains 8.0 Brazilian Version ? Overview For International Consultant

Microsoft Great Plains has substantial mid-market share in the USA plus due to the ... Read More

Databases ? How We Love to Hate Them!

You've finally created databases that you can actually use to store and manipulate... Read More

Should I Use Windows Update?

Should one use Windows Update?This topic has good and valid arguments on both sides. Some... Read More

Microsoft Great Plains Security Setup - Overview For Consultant

Microsoft Business Solutions Great Plains is very good fit for mid-size company and probably good... Read More

The True Meaning of Freeware

The vast majority of us will have, at some point, had freeware games or applications... Read More

Microsoft Great Plains BR: Bank Reconciliation

Microsoft Business Solutions Great Plains is marketed for mid-size companies as well as Navision (which... Read More

Beware of Spyware

One day, you suddenly realize that your computer started to work noticeably slower than it... Read More

SpyBot - Search and Destroy versus Microsoft AntiSpyware (Beta).... My personal experiences...

Ok... Where to start?Well, I guess I will start at the beginning.....Like many surfers and... Read More

The Hidden Power of Online Manual

Writing software manuals is boring, isn't it? We often think: "My software is easy to... Read More

Need of Document Management System (DMS)

Document Management or Enterprise Information Management is perhaps one of the most important of the... Read More

Run Your Own Search Engine

Our hosted solution allow you to run your own search engine.You can have your own... Read More

Microsoft Great Plains Logistics & Warehouse Management ? Implementation & Customization Highlights

Logistics automation is often considered as barcoding extension to Sales Order Processing, Purchase Order Processing,... Read More