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.
![]() |
|
![]() |
|
![]() |
|
![]() |
Microsoft Business Solutions CRM and IBM Lotus Notes Domino, being... Read More
Microsoft has never released a service pack for Windows98 SE,... Read More
Have you noticed WordPerfect is gearing up for a comeback... Read More
After almost two decades of existence, Quark has become the... Read More
eStore Advantage allows front-office applications to communicate with back-office business... Read More
In a previous article, I wrote about OpenOffice... Read More
Microsoft bought Navision, Denmark based software development company, along with... Read More
Microsoft Business Solutions Great Plains has many years of successful... Read More
Find out why Spyware Removal from computers is important and... Read More
When you visit department stores and see that majority of... Read More
Looks like Microsoft Great Plains becomes more and more popular,... Read More
Sales are all about leverage, because there is only so... Read More
GroupwareThe internet is full of 1.5 million to 7 million... Read More
You turn on your computer, and it doesn't look quite... Read More
Finding the best spyware removers to detect and remove spyware... Read More
Microsoft Business Solutions Great Plains is very generic accounting application... Read More
If you have been using the Internet for any amount... Read More
SAP Inc., a global leader in client/server enterprise application software... Read More
Every organization which creates collaborative documents, whether they are budgets,... Read More
Cyberspace has opened up a new frontier with exciting possibilities... Read More
This article will not attempt to advocate the use of... Read More
I have yet to see a business that, sometimes in... Read More
I have always had a tendency to focus on the... Read More
TikiWiki is open source software - it is written in... Read More
With this small article we are continuing Microsoft Business Solutions... Read More
Microsoft Business Solutions ? Navision is an integrated solution for... Read More
If you have Microsoft Great Plains as main accounting and... Read More
Microsoft Great Plains serves majority of US based horizontal and... Read More
As Mozilla Firefox nears 10% market share, with well over... Read More
Microsoft Great Plains and Microsoft Retail Management System (Microsoft RMS)... Read More
It would be easy to think, like most people apparently... Read More
Microsoft Great Plains and Microsoft Retail Management System (Microsoft RMS)... Read More
I have always regretted how Microsoft price gouges and rips... Read More
Looks like Microsoft Great Plains becomes more and more popular,... Read More
Programming Help for BeginnersWe write programs to instruct computers. When... Read More
If you would like to pick something from Microsoft, or... Read More
NOTE: Please take time to read on - it may... Read More
When you own a small business, time is money. And... Read More
Looks like Microsoft Great Plains becomes more and more popular,... Read More
In our case ? we serve Microsoft Business Solutions ERP... Read More
Which Type of Shop Can Rely On A Home Built... Read More
Since technology changes so quickly, it is hard to begin... Read More
We'll give you non formal view, based on our consulting... Read More
As of now - Great Plains Dynamics/eEnterprise is transformed/renamed into... Read More
ERP (Enterprise Resource Planning) Overview covers What is ERP, Brief... Read More
Handling character strings in Java is supported through two final... Read More
The various resume software offered, particularly on the internet, can... Read More
In the Clinton era the status quo was simple: you... Read More
Ok... Where to start?Well, I guess I will start at... Read More
Combining Microsoft Business Solutions Great Plains ERP with non-Microsoft Business... Read More
Microsoft Retail Management (RMS) and Microsoft Great Plains are retail... Read More
Follow the steps below to quickly design, generate, and deploy... Read More
There is many things more frustrating than surfing a website... Read More
SyncUp, a file synchronizer is designed to assist the home... Read More
Microsoft Great Plains serves majority of US based horizontal and... Read More
In this article you will find some background information about... Read More
Microsoft Business Solutions Great Plains, Solomon, Navision, Axapta, Microsoft CRM... Read More
DBxtra is a powerful query and reporting tool that hides... Read More
Disclaimer: All the thoughts expressed are my views only! Your... Read More
Microsoft Great Plains, designed back in 1990th as database transferable... Read More
Did you ever want to erase everything on your computer?... Read More
In our small article we'll consider Microsoft Business Solutions Great... Read More
What is Colossus?Colossus is software licensed to about twenty-five insurance... Read More
Microsoft Great Plains is one of the Microsoft Business Solutions... Read More
Microsoft Business Solutions Great Plains fits to majority of horizontal... Read More
As Mozilla Firefox nears 10% market share, with well over... Read More
Software |