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:

Callidus Software Slips To Wider Q4 Loss
NASDAQ
(RTTNews.com) - Callidus Software Inc. (CALD) reported a fourth-quarter net loss of $3.6 million or $0.11 per share, wider than last year's loss of $1.5 million or $0.04 per share. Last year, results included $1.4 million of stock-based compensation ...
Callidus Software Announces Fourth Quarter and Full Year 2011 ResultsMarketWatch (press release)
Callidus Software, Inc. (CALD) Reports In-Line Q4 EPS; Guides Q1 RevsStreetInsider.com (subscription)

all 12 news articles »


Moxie Software Sponsors Free, Live Webinar on Canon's Best Practices for Field ...
MarketWatch (press release)
Moxie Software, Inc., the Enterprise Social Software Company, today announced it is sponsoring a free, live webinar discussing Canon's Best Practices for Field Service: The New Face of Customer Satisfaction. John Ragsdale, TSIA's vice president of ...

and more »


Guidance Software stock jumps after strong 4Q
CBS News
(AP) NEW YORK — Shares of Guidance Software Inc. rose to their highest level in more than three years Wednesday on strong fourth-quarter results and an upbeat outlook. THE SPARK: After the market closed on Tuesday, Guidance reported net income of $2.3 ...
Guidance Software to Acquire CaseCentralBusiness Wire (press release)
Guidance Software buys CaseCentral for eDiscovery one-two punchFierceContentManagement
Guidance Software Acquires CaseCentralsocalTech.com
Los Angeles Business Journal
all 9 news articles »


Marin Software Promotes Brian Marin and Ed Stevenson to Global Positions
MarketWatch (press release)
SAN FRANCISCO, CA, Feb 08, 2012 (MARKETWIRE via COMTEX) -- Marin Software, provider of the leading online advertising management platform for advertisers and agencies, today announced the promotions of Brian Marin to Vice President, Global Services and ...

and more »


Latitude Software and PaymentVision Offer Integrated Debt Collection and ...
MarketWatch (press release)
GAITHERSBURG, Md., Feb 08, 2012 (BUSINESS WIRE) -- Latitude Software, an Interactive Intelligence Group Inc. company /quotes/zigman/5694010/quotes/nls/inin ININ +0.25% , and PaymentVision have partnered to offer an integrated debt collection and ...

and more »


BMC Software Sells $500 Mln 10-Yr Bonds at 4.316%
Wall Street Journal
By Patrick McGee Of DOW JONES NEWSWIRES NEW YORK (Dow Jones)--BMC Software Inc. (BMC) completed a $500 million sale of 10-year bonds in the US credit markets Wednesday, according to a person familiar with the deal. The 4.25% coupon bonds were priced to ...

and more »


Jive Software Q4 Loss Widens Despite Higher Revenues - Update
NASDAQ
(RTTNews.com) - Enterprise social networking company Jive Software Inc. (JIVE) on Tuesday reported a loss for the fourth quarter that widened from last year as higher costs and expenses offset strong revenue growth. The latest quarterly results are the ...
Jive Software to Present at the Goldman Sachs Technology & Internet Conference ...MarketWatch (press release)
Jive Software reports fourth-quarter lossSan Francisco Chronicle
Jive Financials Show Social Software MomentumInformationWeek
Forbes -TalkinCloud (blog) -RTT News
all 52 news articles »


iWay Software and UBM Global Trade Partner to Automate Legacy Processes for ...
MarketWatch (press release)
NEW YORK, NY, Feb 08, 2012 (MARKETWIRE via COMTEX) -- iWay Software from Information Builders, an innovator of enterprise integration solutions, today announced that UBM Global Trade, a worldwide provider of proprietary data, news, and other content ...

and more »


GigaOm

Akamai Acquires Website Performance Company Blaze Software
TechCrunch
After scooping up rival Cotendo for $268 million recently, content delivery and web services giant Akamai is making another acquisition today—Blaze Software. Blaze's technology helps accelerate speed of Websites, and optimizes load times while cutting ...
Akamai scoops up Canadian software outfitBoston Herald
Akamai Technologies Buys Blaze Software - Quick FactsNASDAQ
Akamai Acquires Venture-Backed Blaze SoftwareTechFinance
Xconomy -Sacramento Bee
all 87 news articles »


Sydney Morning Herald

Google Offers Mobile Chrome Browser for New Android Software
BusinessWeek
7 (Bloomberg) -- Google Inc., seeking to get more of its desktop-computer software onto mobile devices, introduced a test version of its Chrome Web browser for the latest Android operating system. The browser, first unveiled in 2008, will be available ...
Google launches Chrome for Android BetaInquirer
Adobe confirms no Flash for Chrome on AndroidComputerworld
Google releases Chrome beta for AndroidTechnology Spectator

all 515 news articles »

Google News

Home | Site Map

Powered By: Free Work At Home Business Opportunity!

© 2006