Software Information

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.ObjectType.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();

strPartiesXml += "";

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();

strPartiesXml += "";

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.

borism@albaspectrum.com


MORE RESOURCES:

ChattahBox

Facebook Co-Founder To Leave For Own Software Startup
InformationWeek, NY - 1 hour ago
Now, he plans to launch a software startup, according to reports on the Valleywag.com Web site. The Silicon Valley publication said that CEO Mark Zuckerberg ...
Facebook Cofounder Leaving To Start New Company NewsFactor Network
Facebook co-founder quits Siliconrepublic.com
Facebook co-founder calls it quits ITWeb
VentureBeat - Washington Post
all 48 news articles


Patterson Cos. acquires supplier, software maker
CNNMoney.com - 1 hour ago
based Patterson said it was acquiring software company Odyssey Veterinary Software LLC. Patterson shares fell $1.20, or 4.1 percent, to $27.67 in afternoon ...
Patterson Companies Acquires Leading, Value-Added Distributor of ... MarketWatch
Patterson Cos. acquires Columbus Serum Bizjournals.com
Patterson buys Ohio veterinary company Bizjournals.com
all 23 news articles


ZDNet

Sales of RealDVD movie copying software halted by judge
Dallas Morning News, TX - 4 hours ago
Software to do that has existed almost as long as DVD discs, but this is one of the first efforts by a mainstream American company to try to make such ...
RealDVD Sales Suspended In Tinseltown Showdown CRN
RealNetworks Halts Sales of RealDVD PC Magazine
RealDVD sales suspended under court request ITworld.com
Forbes - ZDNet
all 27 news articles


Callidus Software Names Jimmy Duan Senior Vice President of Mid ...
MarketWatch - 7 hours ago
There are tens of thousands of companies in the mid-market segment, which represents a great opportunity for Callidus Software. We are pleased to have Jimmy ...
Callidus Software Schedules Third Quarter 2008 Financial Results ... Business Wire (press release)
Callidus Software Names Jimmy Duan Senior Vice President of Mid ... TMC Net
all 19 news articles


Visual Analytics Achieves Protection Level 3 Certification for its ...
MarketWatch - 4 hours ago
The certification allows the software to operate under DoDDIS, which is managed by the Defense Intelligence Agency (DIA). Under the certification process, ...
Tableau Software Provides Visual Data Analysis Solution for AHIMA TMCnet
Tableau Software and AHIMA to Offer Visual Analytics Software to ... MarketWatch
all 19 news articles


TopCoder Joins Lineups for SD Best Practices and Software Business ...
MarketWatch - 3 hours ago
TopCoder, Inc. today announced its participation in two premier software industry conferences scheduled for the end of October. In Boston, TopCoder will ...


Given Imaging Launches RAPID(R) 5 Access Software
CNNMoney.com - 6 hours ago
Given Imaging Ltd. (NASDAQ: GIVN) today announced the launch of RAPID 5 Access, new software that facilitates physicians' reading PillCam videos anytime, ...
Given Imaging Launches RAPID(R) 5 Access Software MarketWatch
Given Imaging Launches RAPID(R) 5 Access Software International Business Times
all 11 news articles


Dividend.com

SAP Announces 2008 Third Quarter Preliminary Software and Software ...
MarketWatch - 3 hours ago
announced today that after a preliminary review of its 2008 third quarter revenues, it expects third quarter 2008 US GAAP software and software-related ...
Europe's largest software company SAP warns on profits guardian.co.uk
SAP's Third-Quarter Revenue Growth Trails Forecast (Update2) Bloomberg
SAP: first to hit the buffers ZDNet
Reuters UK - guardian.co.uk
all 132 news articles


Healy Hudson Teams With IBM for Software as a Service Solution
MarketWatch - 4 hours ago
have signed a five-year, five million euro Software as a Service contract. As part of the agreement, IBM will support Healy Hudson's e-placing solution ...
Healy Hudson Teams With IBM for Software as a Service Solution International Business Times
IBM opens Scottish data centre CRN - UK
IBM Invests £2 Million in Scotland for New UK Services Business ... International Business Times
all 22 news articles


BBC News

App Store successful, but shows flaws
ITworld.com, MA - 3 hours ago
by Ben Boychuk By all accounts Apple's App Store, which offers add-on software for the iPhone and iPod touch through iTunes, has been a success. ...
iPhone Software 2.2 features emoji, Google Street View, more iLounge
Apple Drops NDA for iPhone Developers eFluxMedia
Dropping the iPhone NDA is good for security ZDNet
TechNewsWorld - InformationWeek
all 369 news articles

Software - Google News

home | site map
© 2006