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 Great Plains is very good fit for... Read More
Research bears that less than 70 percent of development projects... Read More
Are you ready? SQL Server 2005, the next-generation data management... Read More
Microsoft CRM is CRM answer from Microsoft Business Solutions. If... Read More
For a windows user like me, just can watch with... Read More
Microsoft Great Plains has full-featured Manufacturing suite of modules: Capacity... Read More
Today's business world is fast-paced. No matter what it is... Read More
This is the tutorial where we really get into programming.... Read More
Enabling Chinese input is quick and easy, there are only... Read More
When you think... Read More
Considering whether or not your software company should hire a... Read More
In order to implement VLANs in a network environment, you'll... Read More
Microsoft Business Solutions CRM and IBM Lotus Notes Domino, being... Read More
Formatting and reinstalling windows 98 is very easy if you... Read More
Upgrading. Downtime. Maintenance. Hardware obsolescence. Implementation issues. The litany of... Read More
It could just be me, but my experiences with document... Read More
Have you noticed WordPerfect is gearing up for a comeback... Read More
Sometimes your PC will start acting strange for no apparent... Read More
A wiki is an editable text-based website. But you don't... Read More
Let's say that you have a software project that's under... Read More
Customer Relationship Management or CRM is a combination of enterprise... Read More
You probably didn't casually invite, or extend a formal attendance... Read More
Heard about the Quark "killer"?Adobe InDesign CS2. Will it really... Read More
Imagine something that follows you home and sets itself up... Read More
The Windows registry is a huge database that ensures normal... Read More
What is IRC?IRC is Internet Relay Chat. It is a... Read More
The purpose of Project Management Software is to provide an... Read More
This article is for advanced Microsoft CRM SDK C# developers.... Read More
I provide, here clear explanations and a count of function... Read More
Stealing company information used to be the specialty of spies... Read More
Microsoft Great Plains fits to majority of horizontals and retail... Read More
How many steps does it take you to locate and... Read More
Microsoft Great Plains might be considered as ERP platform to... Read More


All your software is stored on a hard-drive. But how... Read More
I like my software simple. If it's too complex or... Read More
Remember back in the days where screensavers were the coolest... Read More
Have you ever noticed that when you look at your... Read More
This is the tutorial where we really get into programming.... Read More
Microsoft CRM is CRM answer from Microsoft Business Solutions.The whole... Read More
So, you've bought a new Macintosh, and now you may... Read More
Buying accounting software is a major investment. It's an important... Read More
Should one use Windows Update?This topic has good and valid... Read More
Small can be beautiful! Working with Knoppix for the past... Read More
Microsoft Great Plains is main Microsoft Business Solutions accounting package... Read More
Microsoft Business Solutions products: Great Plains, MS CRM, Navision, Axapta,... Read More
What is 'adware'?Adware is basically software or scripts that are... Read More
Finding the best spyware removers to detect and remove spyware... Read More
The US House of Representatives has recently passed the "Spy... Read More
Microsoft Business Solutions Great Plains, former Great Plains Software Dynamics... Read More
Looks like Microsoft Great Plains becomes more and more popular,... Read More
The software giants don't do everything and don't always produce... Read More
Each Industry and market niche has business specific and unique... Read More
When you need a phone number, you do a quick... Read More
One day, you suddenly realize that your computer started to... Read More
Sometimes your PC will start acting strange for no apparent... Read More
There are so many different programs that clutter up your... Read More
Upgrading. Downtime. Maintenance. Hardware obsolescence. Implementation issues. The litany of... Read More
Stop the Runaway MouseWhat's the "runaway mouse?" You've seen it...you... Read More
Microsoft Word is one of the most popular office applications... Read More
Microsoft Business Solutions Great Plains and MS CRM (client relation... Read More
Are you one of those people that keeps track of... Read More
Language development computer: Computer-based method for aiding language development seems... Read More
Microsoft CRM and IBM Lotus Notes Domino seem to be... Read More
Microsoft Business Solutions CRM is present several years on the... Read More
The vast majority of us will have, at some point,... Read More
People often ask me: What image file formats will Photoshop... Read More
Software |