Microsoft CRM Programming Secrets ? Tips For Developers

This article is for advanced Microsoft CRM SDK C# developers. It describes the technique of direct SQL programming, when SDK doesn't have the functionality to do the job.

Introduction. Looks like Microsoft CRM becomes more and more popular, partly because of Microsoft muscles behind it. Now it is targeted to the whole spectrum of horizontal and vertical market clientele. It is tightly integrated with other Microsoft Business Solutions products such as Microsoft Great Plains, Solomon, Navision (the last two in progress). Here we describe the technique of creating closed activity-email using MS CRM SDK and direct SQL programming.

Imaging something like this. You need to handle incoming email before it is committed to MS Exchange database. You need to analyze if incoming email doesn't have GUID in its Subject (GUID will allow MS CRM Exchange Connector to move email to Microsoft CRM and attach it to the Contact, Account or Lead) - then you still need to lookup MS CRM in case if one of the accounts, contacts or leads has email address that matches with sender email address - then you need to create closed activity-email in MS CRM, attached to the object and placed into general queue.

How to create MS Exchange handler is outside of the scope, please see this article: http://www.albaspectrum.com/customizations_whitepapers/dexterity_sql_vb a_crystal/exchangehandlerexample.htm

Now the code below is classical MS CRM SDK and it will create activity email:

public Guid CreateEmailActivity(Guid userId, int objectType, Guid objectId, string mailFrom, CRMUser crmUser, 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 += "" + crmUser.GetEmailAddress() + "";

strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otSystemUser.ToString() + "";

strPartiesXml += ""+ crmUser.GetId().ToString("B") + "";

strPartiesXml += "";

strPartiesXml += Microsoft.Crm.Platform.Types.ACTIVITY_PARTY_TYPE.ACTIVITY_PARTY_TO_RECIPIENT.ToString();

strPa rtiesXml += "";

strPartiesXml += "";

strPartiesXml += "";

strPartiesXml += "" + mailFrom + "";

if (objectType == Microsoft.Crm.Platform.Types.ObjectType.otAccount) {

strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otAccount.ToString() + "";

}

else if (objectType == Microsoft.Crm.Platform.Types.ObjectType.otContact) {

strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otContact.ToString() + "";

}

else if (objectType == Microsoft.Crm.Platform.Types.ObjectType.otLead) {

strPartiesXml += "" + Microsoft.Crm.Platform.Types.ObjectType.otLead.ToString() + "";

}

strPartiesXml += ""+ objectId.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 + "rn" + e.StackTrace); } return new Guid(); }

Now I would like to share the trick with you - there is no method to make this activity closed in MS CRM SDK 1.2 (if somebody knows the one - I owe you small pocket aquarium - smile!). Obviously Microsoft doesn't support if you do direct SQL programming bypassing SDK. However I would say this is not direct objects creation - this is rather flags correction. So here is what we have - this procedure will do the job and make activity closed:

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 + "rn" + e.StackTrace);

} }

Happy customizing! if you want us to do the job - give us a call 1-866-528-0577! http://www.albaspectrum.com/customizations_whitepapers/dexterity_sql_vb a_crystal/exchangehandlerexample.htm

Andrew Karasev is Chief Technology Officer in Alba Spectrum Technologies ? USA nationwide Microsoft CRM, Microsoft Great Plains customization company, based in Chicago, Boston, San Francisco, San Diego, Los Angeles, Houston, Atlanta, New York, and Miami and having locations in multiple states and internationally (http://www.albaspectrum.com/customizations_whitepapers/dexterity_sql_vb a_crystal/exchangehandlerexample.htm ), he is Dexterity, SQL, VB/C#.Net, Crystal Reports and Microsoft CRM SDK developer.

family-safe home cleaners Lincolnshire ..
In The News:

Chrome faces its sixth zero-day attack in 2025 as Google patches critical V8 engine flaw CVE-2025-10585 discovered by Threat Analysis Group.
The Hypershell X Ultra exoskeleton features 12 terrain modes and carbon fiber construction to enhance hiking, cycling and outdoor adventures.
Personal data from public records and data brokers helps scammers create tailored scam stories, making their calls and emails more believable to potential victims.
Uber Eats partners with drone delivery startup Flytrex to test autonomous food delivery services in U.S. markets, marking the company's first investment in drone technology.
OpenAI announces 120-day plan to strengthen ChatGPT safeguards for teens, including parental controls and expert council on AI wellbeing.
Spam emails can help improve security — if reported correctly. Learn how to report spam across major email services and get key tips to protect your inbox and personal data.
Harvard researcher Avi Loeb says comet 3I/ATLAS weighs 33 billion tons and spans 3.1 miles, making it far larger than previous interstellar visitors.
The Glassboro Public School District in New Jersey has partnered with ZeroEyes and InformaCast to detect visible firearms and alert staff and law enforcement within seconds.
Hackers use fake Google search results to trick users into downloading lookalike apps laced with malware that have been pushed to the top.
Generative A.I. has lowered barriers for sophisticated cyberattacks as hackers exploit ChatGPT and other tools to forge documents and identities.
IOS 26's new features include bigger lock screen clocks, dirty lens alerts, and improved spam detection for iPhones.
Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
Sophisticated phishing scams now exploit Apple's iCloud Calendar invite system to bypass spam filters and trick users into calling fake support numbers.
Complete guide to medication tracking apps for iPhone and Android users, featuring built-in Health apps, MediSafe, MyTherapy, and smart pill dispensers.
Alef Aeronautics plans to begin production of its electric flying car Model A by late 2025, following FAA approval for limited testing at five airport locations.
Five common overpayment scams use fake checks and third-party payment requests to steal money from unsuspecting victims across various scenarios.
The Robeta Ananya luxury camper van features a full living room, ceiling bed, washer-dryer, and complete kitchen starting at $295,000 for the limited Founders' Edition.
Scammers exploit retirees' trust and assets through fake debt collection calls, but proper verification methods and reporting can stop these fraudulent schemes.
Social media scams are rising as fraudsters create fake accounts and buy verification badges to deceive users, but these simple safety steps can protect you.
The new groundbreaking Paris Solar-Battery Park in Wisconsin provides renewable energy day and night by capturing excess energy from its solar panels.
Travelers face increased risks from fake Wi-Fi networks at airports and on flights as attackers exploit growing reliance on in-flight internet for entertainment and services.
Older Android phones, tablets and car systems will lose access to new Waze features as the app drops support for Android versions below 10.
Research shows iPhone owners' overconfidence in Apple security makes them easier targets for cybercriminals compared to Android users who take more precautions.
Five key tech terms reshaping online shopping from mobile payments and instant delivery to social media commerce and inventory-free retail models.
AI browsers from Microsoft, OpenAI and Perplexity can fall for scams faster than humans, completing fraudulent purchases and clicking malicious links without verification.

eCommerce development for Microsoft Great Plains: tools and highlights for programmer

Microsoft Business Solutions Great Plains, former Great Plains Software Dynamics... Read More

Microsoft Great Plains SOP: Sales Order Processing

Microsoft Business Solutions Great Plains is marketed for mid-size companies... Read More

Most Dangerous Types of Spyware are on the Rise: How to Choose the Weapon

Bad News - the Threat is Bigger than it SeemedHow... Read More

Falling in Love With More Than One Screensaver: The Fun Part

Having from five to ten and more favorite screensavers is... Read More

Corporate Accounting System: Microsoft Great Plains ? Overview

Corporate ERP/MRP selection might be tough one, especially considering very... Read More

Helping Newbies Understand Professional Software

The Windows registry is a huge database that ensures normal... Read More

Microsoft Great Plains Customization and Development ? Overview for Programmer

When Great Plains Software was designing and developing Great Plains... Read More

The Top 5 Wrong Reasons For Not Hiring Testers

Considering whether or not your software company should hire a... Read More

SQL: Querying Microsoft Great Plains ? Overview for Database Administrator/Developer

Looks like Microsoft Great Plains becomes more... Read More

OS 101: Suggestions for Choosing an Operating System

An operating system (abbreviated OS) is essentially the path through... Read More

Microsoft Great Plains Security Setup - Overview For Consultant

Microsoft Business Solutions Great Plains is very good fit for... Read More

Adware, What Is It?

Adware is a type of Spyware program that displays some... Read More

Lotus Domino/Notes - Microsoft Great Plains Tandem as ERP with Documents Workflow - Overview for IT

Lotus Domino/Notes ? Microsoft Great Plains tandem as ERP with... Read More

Looking for an Alternative to Microsoft Office? You Should Be!

Now is the time to look at an alternative to... Read More

Microsoft CRM USA Nationwide Remote Support

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

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

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

Running a Program on a Remote Server Using SSH

How do you run a program on a remote server... Read More

Microsoft CRM Development

Microsoft CRM is CRM answer from Microsoft Business Solutions.The whole... Read More

Programming Environments And The Software Production Process

Introduction: The creating of a computer program involves a number... Read More

Spyware Statistics -- Whats New in May 2005?

Although statistics often is blamed for various deadly sins --... Read More

Introducing GRML

Creating a new markup language.Introduction.General Reuse Markup Langauge, or GRML,... Read More

Microsoft Great Plains PM: Payables Management

Microsoft Business Solutions Great Plains is marketed for mid-size companies... Read More

Internet Security Threats: Who Can Read Your Email?

Before being able to choose a secure Internet communication system,... Read More

Antivirus Software ? Get The Bugs Before They Get You!

You turn on your computer, and it doesn't look quite... Read More

Free Microsoft Word Online Training Tutorial Resources

Microsoft Word is one of the most popular office applications... Read More

after renovation cleaning Bannockburn ..