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 part III of this ISDN primer, we learned that... Read More
Lotus Domino/Notes ? Microsoft Great Plains tandem as ERP with... Read More
Spyware is like the new technological nuclear weapon on the... Read More
Do you want to get quality software at a reasonable... Read More
Program Flow is what you think it is. How the... Read More
Microsoft Business Solutions Great Plains has many years of successful... Read More
The research in the field of Natural Language Processing usually... Read More
C++ Function templates are those functions which can handle different... Read More
Are you ready? SQL Server 2005, the next-generation data management... Read More
Customer Relationship Management (CRM) is a strategy and processes used... Read More
When Great Plains Software was designing and developing Great Plains... Read More
Microsoft Great Plains is main mid-market application from Microsoft Business... Read More
Mapping Software Improves Data VisualizationFrom the outset, it is important... Read More
According to a survey conducted by InfoTrends/CAP Ventures entitled "Content-Centric... Read More
If you're online using a dialup Internet connection, you'll probably... Read More
To all web designers out there, this article is for... Read More
Microsoft Great Plains is becoming more and more popular and... Read More
Features Additionally, Vista will include many other new features.Aero Vista... Read More
If you have Microsoft Great Plains and support it... Read More
Almost all new and major brand of PCs come with... Read More
Our company, Novaprof Inc., developed unique software - DB Integration.... Read More
It is possible that if one avoided all sources of... Read More
The world of small business accounting software can be a... Read More
Spyware and malware are large problems for Internet users today... Read More
This article is for advanced Microsoft CRM SDK C# developers.... Read More
Let us give you - developer some hints in the... Read More
Microsoft Word is one of the most popular office applications... Read More
SyncUp, a file synchronizer is designed to assist the home... Read More
Just imagine: you are walking, say, towards your car, and... Read More
After almost two decades of existence, Quark has become the... Read More
Running Applications in Compatibility Mode With Windows XP, you can... Read More
Using professional icons in your application or website can bring... Read More
In this short FAQ style article we would like to... Read More
Current Microsoft Business Solutions Great Plains has more that 10... Read More
Microsoft CRM is CRM answer from Microsoft Business Solutions. If... Read More
Combining Microsoft Business Solutions Great Plains ERP with non-Microsoft Business... Read More
When it comes to running an office, the SOHO entrepreneur... Read More
Microsoft Business Solutions Great Plains, former Great Plains Software Dynamics/eEnterprise... Read More
It is possible that if one avoided all sources of... Read More
Now that spyware is the single most dangerous threat to... Read More
Great Plains Integration Manager scripting and translation - overview for... Read More
GroupwareThe internet is full of 1.5 million to 7 million... Read More
There are several kinds of software piracy. The bottom line... Read More
Collaboration SoftwareCollaboration Software, also known as group collaboration software or... Read More
Need software to record your voice, streaming audio or musical... Read More
Internet worms. Is your PC infected?If your computer has become... Read More
Microsoft Client Relation Management system (Microsoft CRM) and Microsoft RMS... Read More
RSS (Really Simple Syndication) is a way for a site... Read More
Microsoft Business Solutions CRM is present several years on the... Read More
There are two major WYSIWYG(What You See Is What You... Read More
Microsoft CRM is now on the scene and it is... Read More
Microsoft Business Solutions offers several ERP applications: Great Plains, Navision,... Read More
Every day millions of new web documents emerge on the... Read More
Microsoft Great Plains is becoming more and more popular and... Read More
Have you noticed WordPerfect is gearing up for a comeback... Read More
Spyware and Adware infest over 90 percent of computers in... Read More
Although we don't know whether Microsoft ever envisioned such a... Read More
Microsoft Business Solutions ? Navision is an integrated solution for... Read More
The software giants don't do everything and don't always produce... Read More
Fleet Maintenance Management is a critical position in any company... Read More
Simply put, fleet maintenance allows companies to monitor and maintain... Read More
This is a short article, written in question/answer/FAQ style to... Read More
Microsoft released Service Pack 2 (SP2) for the Windows XP... Read More
Finally, you have some time to personalize your desktop with... Read More
During the years of our consulting practice, which comes back... Read More
Adware is a type of Spyware program that displays some... Read More
Software |