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.ObjectTy pe.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();
strPa rtiesXml += "";
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();
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 + " " + 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.
![]() |
|
![]() |
|
![]() |
|
![]() |
How many steps does it take you to locate and... Read More
Many Webmasters have never bothered to view their website's server... Read More
Microsoft CRM is relatively new player on the now becoming... Read More
SyncUp, a file synchronizer is designed to assist the home... Read More
Adobe Photoshop is one of the world's leading graphics editing... Read More
With many manufacturing shops heading over seas in favor of... Read More
Not all of us have the luxury of working both... Read More
In 2004 Oracle, Inc. made its new step toward J2EE... Read More
You probably didn't casually invite, or extend a formal attendance... Read More
Spyware, what it is and what it does. Basically, spyware... Read More
What is Software?Software is a set of instruction written to... Read More
It is a well known fact that Java as a... Read More
What is IRC?IRC is Internet Relay Chat. It is a... Read More
Preventive Maintenance (PM) is defined as scheduled work done on... Read More
While I was in college, if you would have asked... Read More
Customer Relationship Management (CRM) is a strategy and processes used... Read More
How would you like to prevent spyware and adware from... Read More
This article is the third of a series of articles... Read More
For a windows user like me, just can watch with... Read More
Microsoft Great Plains, Navision, Solomon and Axapta are Microsoft Business... Read More
If you look back to the history, you will see... Read More
Usually, the easiest way to tell you have spyware is... Read More
Before September of 1995, Microsoft ignored the Internet because their... Read More
Before September 1995, Microsoft Windows was an MS-DOS program. DOS... Read More
Looking at all the ads which promise to get rid... Read More
Microsoft CRM and IBM Lotus Notes Domino seem to be... Read More
Table of Contents1) Introduction 2) Related Work 3) Framework 4)... Read More
The Windows Indexing Service provides you with the ability to... Read More
Microsoft Business Solutions Great Plains is very good fit for... Read More
This tutorial covers OLAP solutions used by Data warehouses and... Read More
Microsoft Business Solutions Great Plains is marketed for mid-size companies... Read More
The objective for Zandi Digital is to make available clever... Read More
Whether you need to close a sale, gather end-user feedback,... Read More
NOTE: Please take time to read on - it may... Read More
When Great Plains Software introduced the first graphical accounting application... Read More
Our hosted solution allow you to run your own search... Read More
Do you remember that frustrating feeling when you find an... Read More
One of the main reasons business owners and entrepreneurs use... Read More
Accounts payable is just one area of office management where... Read More
Designing without tables by using CSS layouts is fast becoming... Read More
Once a business idea is selected, it is highly recommended... Read More
When you think... Read More
Anti-virus software is used to find, remove or fix files... Read More
1. With mapping software you can create a report that... Read More
Sometimes your PC will start acting strange for no apparent... Read More
Ad-Aware and Spybot are probably the two most well known... Read More
This tutorial covers OLAP solutions used by Data warehouses and... Read More
For a long time now Microsoft's Internet Explorer has ruled... Read More
In the case when you represent mid-size or mid-size-to-large business,... Read More
There are several kinds of software piracy. The bottom line... Read More
Microsoft Client Relation Management system (Microsoft CRM) and Microsoft RMS... Read More
Are you ready? SQL Server 2005, the next-generation data management... Read More
The vast majority of us will have, at some point,... Read More
Microsoft Retail Management (RMS) and Microsoft Great Plains are retail... Read More
When you double-click a layer in the Layer Palette, you... Read More
SAP Inc., a global leader in client/server enterprise application software... Read More
All of us know that Microsoft bought former Great Plains... Read More
Did you ever give a thought to the number of... Read More
This article is the fourth of a series of articles... Read More
Internet worms. Is your PC infected?If your computer has become... Read More
You've finally created databases that you can actually use to... Read More
FTP stands for "file transfer protocol". FTP is basically a... Read More
Microsoft Business Solutions Great Plains, former Great Plains Software Dynamics... Read More
During the years of our consulting practice, which comes back... Read More
Vince Lombardi once said that, "The achievements of an organization... Read More
Passwords protect your most sensitive personal, financial and business information.... Read More
Software |