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

Bradley bmw rental chicago .. Lockport Chicago limo O’Hare
In The News:

Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
Tech expert Kurt “CyberGuy" Knutsson says a new autonomous AI is a game changer that also raises privacy risks. Is your data safe?
Tech expert Kurt “CyberGuy" Knutsson says robots and drones are revolutionizing fruit farming with faster picking and smarter handling.
Landmark Admin revises May 2024 cyberattack scope to show twice as many people were affected. Kurt “CyberGuy" Knutsson gives tips to help stay safe from an insurance data breach.
Tech expert Kurt “CyberGuy" Knutsson talks about how Yamaha’s hydrogen outboard motor could revolutionize boating with zero emissions.
Tech expert Kurt “CyberGuy" Knutsson reveals how to memorialize or remove a deceased loved one’s Facebook account and protect their digital legacy from misuse or scams.
Tech expert Kurt “CyberGuy" Knutsson says an Apple Watch saved psychiatrist Amanda Faulkner by detecting deadly leukemia early.
Scammers and fraudsters are increasingly targeting the most vulnerable, especially nursing homes and the personal data of their residents. Kurt the CyberGuy has safety tips.
Infected USB flash drives can spread malware among multiple organizations in ways that can easily bypass traditional security systems.
With a fully automated warehouse system and AI-powered robots, Ocado's Hive picks, packs and delivers grocery store orders in just a few minutes.
Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
Recycling robots are using artificial intelligence to learn how to sort recyclables by recognizing patterns in colors, textures, shapes and logos.
The Reachy 2 robot is designed to be friendly and approachable, inviting natural interaction and is perfect for research, education and experimenting with embodied AI.
Kurt "CyberGuy" Knutsson shares several easy ways to keep your credit cards safe from digital thieves while you're traveling this summer.
Arcturus sets up cameras around the edges of baseball stadiums to capture real-time action and generate a 3D digital clone of the game.
Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
The CyberGuy explains why healthcare organizations are vulnerable to hackers after there have been a half dozen data breaches this year.
Developed at two California universities, the innovative technology combines brain-computer interfaces with advanced AI to decode neural activity into audible speech.
Microsoft patches 12 critical flaws, but six have already been exploited by criminals. Kurt “CyberGuy" Knutsson says updating your system is only a short-term fix.
Tech expert Kurt “CyberGuy" Knutsson discusses how robots can milk, feed and clean cows on dairy farms, boosting efficiency and comfort.
Tech expert Kurt “CyberGuy" Knutsson says quantum internet ensures unhackable security and redefines online privacy and speed.
Kawasaki's CORLEO is a hydrogen-powered, AI-driven rideable robot. Tech expert Kurt “CyberGuy" Knutsson reports on this new way of thinking about off-road transportation.
The CyberGuy breaks down five mobile privacy terms that could make a difference when it comes to keeping your personal information safe.
A groundbreaking robot that's like a real-life Wall-E uses advanced artificial intelligence to replicate natural gestures and deliberate actions with striking accuracy.
If not properly managed, Windows Defender Application Control, a security feature with Windows, could be a potential security vulnerability.

Microsoft Great Plains Customization Tools ? Overview

Former Great Plains Software Dynamics/eEnterprise, and currently Microsoft Business Solutions... Read More

Microsoft Great Plains Partner Selection: Overview

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

How To Make Good Use of Spreadsheets

Most computer users use spreadsheets software such as Microsoft Excel... Read More

Microsoft CRM Custom Design & Development: SDK, C#, SQL, Exchange, Integration, Crystal Reports

Microsoft CRM is new player on the CRM software... Read More

Free PDF Publishing Software

In a previous article, I wrote about OpenOffice... Read More

Windows Screensavers Explained

In this article you will find some background information about... Read More

Microsoft Great Plains Implementation for Midsize & Large Corporation: Lockbox Processing

Microsoft Great Plains is now targeting large and midsize businesses... Read More

Microsoft Great Plains customization ? Freight Forwarding/Transportation industry example

Microsoft Business Solutions Great Plains version 8.5, 8.0, 7.5, Great... Read More

Dreamweaver vs FrontPage

There are two major WYSIWYG(What You See Is What You... Read More

International Support - Microsoft Great Plains VAR/Partner Selection ? Overview for V.P. IT

Looks like Microsoft Great Plains becomes more and more popular,... Read More

ERP Remote Support: Microsoft Great Plains Analysis ? Pluses & Minuses

Former Great Plains Software Dynamics/eEnterprise and currently Microsoft Business Solutions... Read More

SyncUp ? A File/Folder Synchronizer For Windows

SyncUp, a file synchronizer is designed to assist the home... Read More

Microsoft Great Plains: Interest Calculation Example ? Stored Procedure for Crystal Report

This is intermediate level SQL scripting article for DB Administrator,... Read More

How a Bug Challenges to a Software Professional

It is really interesting that a bug can create problem... Read More

HSphere Control Panel Tips and Tricks - Power At Your Fingertips: Part 1

The first topic we are going to discuss... Read More

Making The Decision To Automate Your Software Testing

Not every software testing project can or should be automated.... Read More

QuarkXpress Tips: How to Move Content Between Print and Web Layouts

Since its release in 1987, QuarkXpress had made an immediate... Read More

XML Parser and Their Types

XML parser is a software module to read documents and... Read More

Where to Find Free Fleet Maintenance Software

Costs of fleet maintenance software can vary widely. It is... Read More

Crystal Reports - Geterogeneus databases: SQL Server, Oracle, Unidata, Btrieve ? Tips For Developer

Crystal Reports is the most flexible tool on the market... Read More

Database Guru James F. Koopmann Reviews DBxtra Reporting and Query Tool

DBxtra is a powerful query and reporting tool that hides... Read More

Software Process Improvement -A Successful Journey

Background: For many organizations like ours, the interim target of... Read More

Beware of Spyware

One day, you suddenly realize that your computer started to... Read More

Data Quality Best Practices for Salesforce.com

Executive SummaryAn effective plan for entering, cleaning and updating the... Read More

Software Companies: Generate New Revenue Streams and Decrease Costs with Custom e-Learning Content

It's no secret that software companies operate in a very... Read More

prom limo McHenry ..