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.
![]() |
|
![]() |
|
![]() |
|
![]() |
In our case ? we serve Microsoft Business Solutions ERP... Read More
The term "document management" and "paperless office" is the subject... Read More
You have gotten those E_Mails buy software at deep discounts.... Read More
Looking at all the ads which promise to get rid... Read More
XML Server can be a Web Server that stores the... Read More
#5 All your hardware components like Printers, PCs etc come... Read More
Remember old good days when your company probably had Great... Read More
Corporate ERP/MRP selection might be tough one, especially considering very... Read More
How to delete the user? This is the first problem... Read More
Microsoft CRM is CRM answer from Microsoft Business Solutions.The whole... Read More
There are two major WYSIWYG(What You See Is What You... Read More
Some introduction into Great Plains Software products, now Microsoft Business... Read More
In this short FAQ style article we would like to... Read More
If you have been using the Internet for any amount... Read More
Although statistics often is blamed for various deadly sins --... Read More
Looks like Microsoft Great Plains becomes more and more popular,... Read More
Currently Microsoft Business Solutions is on the way of creating... Read More
In part III of this ISDN primer, we learned that... Read More
Microsoft Retail Management System serves retail single store as well... Read More
Microsoft Great Plains could be tuned and setup to fit... Read More
Just imagine: you are walking, say, towards your car, and... Read More
Microsoft Business Solutions products: Great Plains, MS CRM, Navision, Axapta,... Read More
Stop the Runaway MouseWhat's the "runaway mouse?" You've seen it...you... Read More
Microsoft Business Solutions Great Plains, former Great Plains Software eEnterprise,... Read More
Intro This concise article will tell you in plain English... Read More
Microsoft Business Solutions Great Plains has I'd say end user... Read More
It is really interesting that a bug can create problem... Read More
I started using PIP (Picture It Publishing) Platinum 2002 right... Read More
Buying accounting software is a major investment. It's an important... Read More
1. What determines the software price? Is it Per Seat... Read More
When you first think about multicurrency ? you probably have... Read More
If you are in a business that passes documents around... Read More
The fact that a software tester is a most infamous... Read More
Are you a database professional? Do you work with a... Read More
Most people understand that the "hardware" part of their computer... Read More
In this small article we will show you the possible... Read More
Microsoft Business Solutions CRM is present several years on the... Read More
Microsoft Great Plains and Microsoft Retail Management System (Microsoft RMS)... Read More
The Windows Indexing Service provides you with the ability to... Read More
Customer Relationship Management or CRM is a combination of enterprise... Read More
C/SIDE (Client/Server Integrated Development Environment) - The core of... Read More
SAP Inc., a global leader in client/server enterprise application software... Read More
DBxtra is a powerful query and reporting tool that hides... Read More
Microsoft Business Solutions Great Plains, former Great Plains Software eEnterprise,... Read More
I have always regretted how Microsoft price gouges and rips... Read More
Follow the steps below to quickly design, generate, and deploy... Read More
Microsoft Great Plains as ERP and Microsoft CRM as... Read More
If you are in the market for new staffing software,... Read More
What is RAID RECOVERY?RAID stands for Redundant Array of Inexpensive... Read More
Microsoft Great Plains is main mid-market application from Microsoft Business... Read More
We would like to give you several situations, when you... Read More
Former Great Plains Software Dynamics/eEnterprise and currently Microsoft Business Solutions... Read More
COMMAND LINE FUNCTIONA powerful command line script processor has been... Read More
When you visit department stores and see that majority of... Read More
Microsoft Business Solutions Great Plains is very good fit for... Read More
Microsoft Business Solutions Great Plains, former Great Plains Software Dynamics... Read More
In order to meet regulatory and corporate compliance requirements reporting... Read More
We've all seen the ads on TV for Netzero 3G.... Read More
User interfaces and accessibility are some of the most important... Read More
Every organization which creates collaborative documents, whether they are budgets,... Read More
Microsoft CRM was designed to be easily customizable. Microsoft CRM... Read More
In the Clinton era the status quo was simple: you... Read More
Since Version 8.0 Microsoft Business Solutions Great Plains & Great... Read More
When Great Plains Software introduced the first graphical accounting application... Read More
TCO (Total Cost Ownership) is the buzzword in... Read More
In the case when you represent mid-size or mid-size-to-large business,... Read More
Software |