Microsoft CRM Customization ? Programming Closed Email Activity

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 (help@albaspectrum.com), he is Microsoft CRM SDK, C#, VB.Net, SQL, Oracle, Unix developer. Boris can be reached: 1-866-528-0577 or help@albaspectrum.com.

help@albaspectrum.com

shuttle from O'Hare Bingham .. Lockport Chicago limo O’Hare
In The News:

Attackers use caller ID spoofing and AI voices to steal money. Tech expert Kurt “CyberGuy" Knutsson provides seven ways to protect yourself.
Tech expert Kurt “CyberGuy" Knutsson talks about the Genesis GV60 MIV, an electric rescue EV with snow tracks for extreme missions.
Tech expert Kurt “CyberGuy" Knutsson helps you ensure a smooth online experience with a reliable, secure home network setup.
Kurt “CyberGuy" Knutsson talks about Vollebak’s Shielding Suit, which blocks EM radiation, infrared and tracking for privacy.
Even Apple products are vulnerable to cybercriminals, and a new report suggests the owners of Mac products will have to be more vigilant this year.
An inflatable six-person tiny house from a firm called 2001 looks like a space station with its inflatable dome that is transportable and eco-friendly.
Scams cost Americans an estimated $159 billion every year and average about $3,500 in losses per victim. The CyberGuy has advice to protect yourself.
Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents
Zeekr and Waymo are joining forces for the world's first mass-produced autonomous vehicle, combining an electric vehicle with self-driving technology.
A humanoid robot training center has opened in Shanghai, a big step in China's efforts to become a global leader in robotics and artificial intelligence.
Security experts have discovered that hackers are targeting apps on the App Store to spread malware that steals information from saved screenshots.
A new luxury SUV combines military-inspired design and high-end luxury transportation and includes two military-grade gas masks to protect against chemical warfare.
80% of stalking victims are tracked using tech. GPS trackers, like AirTags, are among the most popular ways to do it. Here's how to protect yourself.
Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
Kurt "CyberGuy" Knutsson explains how to protect yourself against artificial intelligence-fueled romance scams, which have become the most common type of fraud in 2025.
Kurt "CyberGuy" Knutsson explains the steps to declutter text messages on a Mac or iPad. Apple offers ways to do this more efficiently.
Here's how to take control of the algorithms on Facebook, YouTube, Instagram and TikTok if your social media feeds aren't showing you content you want to see.
Beware of iCloud scams using urgent messages. Tech expert Kurt “CyberGuy" Knutsson helps you spot the red flags to protect yourself.
Travel abroad worry-free with these top translation apps for travelers. Tech expert Kurt “CyberGuy" Knutsson highlights some favorites.
The European Space Agency's Euclid space telescope was going through preliminary tests in September 2023 when it captured images of an Einstein Ring in a nearby galaxy.
Tech expert Kurt “CyberGuy" Knutsson says hackers are using Microsoft Teams for phishing, vishing and quishing via social engineering.
Red light camera tickets: Not liable to ID the driver; some are fishing expeditions. Tech expert Kurt “CyberGuy" Knutsson helps you fight back against tricky fake tickets.
The apps collecting the most data about you are among the most widely used. Kurt the CyberGuy takes a look at 20 of these apps and how you can protect personal information.
AST SpaceMobile of Texas is developing the world's first global cellular broadband network that can connect directly to your smartphone without special equipment.
Community Health Center, a Connecticut-based healthcare provider, has disclosed a recent data breach affecting over 1 million people in the U.S.

Navision Customization: C/SIDE, C/ODBC, C/FRONT, XBRL ? Development Options

Microsoft bought Navision, Denmark based software development company, along with... Read More

Is Your Computer Sick?

Viruses and spyware usually show up on your computer one... Read More

Create ASP in Minutes

DBxtra goes ASPGetting to the information hidden within corporate databases... Read More

Linux for Home Users

Hey Guys! Don't raise your eyebrows or fear by hearing... Read More

Daffodil DB: Web Database

What is a Web Database?A web database is a database... Read More

Instant Messaging is a Sweet Way to Communicate

MSN messenger is a pretty cool invention. I mean I'm... Read More

10 Things You Can Do With Photoshop CS2 That You Couldnt Do Before Now

Is Photoshop CS2 worth the upgrade? You bet it is!... Read More

Microsoft CRM Conversation Gateway: VoIP - Implementation & Customization

Microsoft CRM is winning market share step-by-step from such the... Read More

Software Upgrades Arent Always the Best Move

When my daughter was getting into AOL instant messaging (AIM)... Read More

Microsoft Great Plains: Data Conversion & Migration Scenarios ? Overview for Consultant

Microsoft Business Solutions Great Plains serves multiple industries in the... Read More

C++ Tutorials: 3, Program Flow (If, Else, While, For)

Program Flow is what you think it is. How the... Read More

Free Software for Newbies and Web Developers

Here is some free software tools to help you build... Read More

Microsoft CRM USA Nationwide Remote Support

Remember old good days when your company probably had Great... Read More

Twelve Things You Should Know to Save on Computer Software

Do you want to get quality software at a reasonable... Read More

eConnect: eCommerce Development for Microsoft Great Plains

Microsoft Business Solutions Great Plains has several options to enable... Read More

Who?s Watching What You Type?

If someone entered your home, uninvited and installed numerous cameras... Read More

Great Plains Custom Development: Dexterity, VBA, SQL, Crystal, eConnect ? Overview For Programmer

Microsoft Great Plains is main Microsoft Business Solutions accounting package... Read More

Microsoft Great Plains Integration with Microsoft Access ? Overview for Developer

... Read More

Behave, Word, Behave!

If you copy something from a Web site or elsewhere...... Read More

10 Steps To Secure And Manage Your Passwords

Passwords protect your most sensitive personal, financial and business information.... Read More

Groupware: Avoid the Ad Hoc Shuffle

GroupwareEfforts are continually made to manage the unavoidable ad hoc... Read More

Is Software Tester a Most Infamous Person in a Software Project Team?

The fact that a software tester is a most infamous... Read More

Cisco Certification: Introduction To ISDN, Part V

The major reason I recommend getting your hands on real... Read More

Microsoft Great Plains: Large Scale Implementation

Microsoft Business Solutions Great Plains, Navision, Axapta, Solomon and CRM... Read More

Microsoft CRM Data Import FAQ

Microsoft CRM has built-in conversion tool, however you should probably... Read More

Mishawaka limo O'Hare ..