Microsoft CRM Customization – programming Closed E

Microsoft CRM Customization – programming Closed Email Activity

by: Boris Makushkin

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 email 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 18665280577! 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: 18665280577 or borism@albaspectrum.com.

borism@albaspectrum.com

This article was posted on October 25, 2004

by Boris Makushkin

Worn Out Brochure Design Is Keeping Small Business

Worn Out Brochure Design Is Keeping Small Business Owners Down

by: John Jantsch

I got another one of those calls the other day…Can you make me a brochure?ก Many business owners have been sold on the notion that they need a trifold brochure or they are not in business. Forget it…everybodyกs got one and no one uses it.

Your potential clients need an education. They need to know how you are different. (The typical trifold brochure simply confirms that you are the same.)

Every small business should create the following pieces of information and format them in a way that allows them be printed inexpensively and updated often. I like to call this approach, the Marketing Kit. Your marketing kit starts with several professionally printed pieces that are the framework for up to 10 or 12 different educational documents. The core components are:

1. A pocket folder A multiuse workhorse, this piece alone, if designed well, can send the message that you are in business to stay. (This one will cost a little but it has many uses)

2. A marketing template This should be a professionally printed piece that carries your logo and contact information but is different than your letterhead. This is the base piece then for the following pages that insert into your pocket folder. Your actual marketing files can be MSWord type documents that are laser printed. This gives you the ability to change and update your content and also allows you to tailor your marketing kit content to specific prospects.

Some combination of the following pages should be created for your marketing kit.

+ The Difference Page Hit them with how you are different and shower them with benefits of doing business with you. Don’t tell them what you do. I like to keep this one to the top 3 or 4 things that you do that your target market will value. Think benefits that are unique

+ A list of services Okay, now tell them what you do or what you offer.

+ Case Studies Pick representative clients or industries and outline how your product or service solved someone elseกs challenge. People learn in different ways and case studies allow them to see themselves getting relief. I think this format works well. State the situation, the problem, your solution, the result. Over time you can collect more and more of these and draw upon the ones that fit an industry or problem that in relevant to your prospect.

+ Testimonials Get quotes from real live clients and create a page titled กSee what others have to say about us.ก These quotes can be some of the strongest selling tools you have. New technologies make it easy to create audio and video testimonials too.

+ Process Description Show them how you do what you do. Create detailed checklist and flow charts that show them how you keep your promise. In many cases you have these anyway but by making them part of your marketing you can demonstrate how much more professional your organization is. These also help you justify why you charge a premium for your services. Many people underestimate how much really goes into delivering a quality product or service. So show them.

+ Your Story Many companies have interesting or even gut wrenching histories. Tell them your story in an open, honest, and entertaining way and you will win their hearts as well as their heads.

All of the above pieces can, in many cases, be word processed files that are laser printed onto the template I described above. You can learn even more about how to use this unique tool here

This format allow for very inexpensive printing and a great deal of flexibility when you need to update, change or even personalize your magnificent marketing materials.

Want to quickly create your own magnificent marketing materials. Join me as I coach up to 10 other small business owners through the process of creating marketing materials that educate and sell. Once a week for 4 weeks we will meet via teleconference to create and critique your written marketing kit content based on the above article. Each participant will also receive a workbook, feedback and reallife example marketing kits produced by John Jantsch for his clients. Find out more by sending an email to mailto:john@ducttapemarketing.com?subject=Marketing_Kit

Copyright 2004 John Jantsch

About The Author

John Jantsch is a marketing coach and creator of the Duct Tape Marketing System. You can get more information about the Duct Tape System and download your free copy of ขHow To Create the Ultimate Small Business Marketing System in 7 Simple Stepsข by visiting http://www.DuctTapeMarketing.com.

This article was posted on December 02, 2004

by John Jantsch

Microsoft Great Plains: Interest Calculation Examp

Microsoft Great Plains: Interest Calculation Example – stored procedure for Crystal Report

by: Andrew Karasev

This is intermediate level SQL scripting article for DB Administrator, Programmer, IT Specialist

Our and Microsoft Business Solutions goal here is to educate database administrator, programmer, software developer to enable them support Microsoft Great Plains for their companies. In our opinion self support is the goal of Microsoft to facilitate implementation of its products: Great Plains, Navision, Solomon, Microsoft CRM. You can do it for your company, appealing to Microsoft Business Solutions Techknowledge database. This will allow you to avoid expensive consultant visits onsite. You only need the help from professional when you plan on complex customization, interface or integration, then you can appeal to somebody who specializes in these tasks and can do inexpensive nationwide remote support for you.

Letกs look at interest calculation techniques.

Imagine that you are financing institution and have multiple customers in two companies, where you need to predict interest. The following procedure will do the job:

CREATE PROCEDURE AST_Interest_Calculation

@Company1 varchar(10), Great Plains SQL database ID

@Company2 varchar(10),

@Accountfrom varchar(60),

@Accountto varchar(60),

@Datefrom datetime,

@Dateto datetime,

as

declare @char39 char for single quote mark

declare @SDatefrom as varchar(50)

declare @SDateto as varchar(50)

select @SDatefrom = cast(@Datefrom as varchar(50))

select @SDateto = cast(@Dateto as varchar(50))

select @char39=char(39)

if not exists (select * from dbo.sysobjects where id = object_id(Nก[dbo].[AST_INTEREST_TABLE]ก) and OBJECTPROPERTY(id, NกIsUserTableก) = 1)

CREATE TABLE [dbo].[AST_INTEREST_TABLE] (

[YEAR] [int] NULL ,

[MONTH] [int] NULL ,

[COMPANYID] [varchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,

[ACTNUMST] [char] (129) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,

[BEGINDATE] [varchar] (19) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,

[ENDDATE] [varchar] (19) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,

[YEARDEGBALANCE] [numeric](19, 5) NULL ,

[BEGBALANCE] [numeric](38, 5) NULL ,

[ENDBALANCE] [numeric](38, 5) NULL ,

[INTERESTONBALANCE] [numeric](38, 6) NULL ,

[INTERESONTRANSACTIONS] [numeric](38, 8) NULL ,

[INTEREST] [numeric](38, 6) NULL

) ON [PRIMARY]

exec(ก

delete AST_INTEREST_TABLE where [YEAR] = year(ก+ @char39 + @Datefrom + @char39 +ก) and [MONTH]=month(ก+ @char39 + @Datefrom + @char39 +ก)

insert into AST_INTEREST_TABLE

select

year(X.BEGINDATE) as [YEAR],

month(X.BEGINDATE) as [MONTH],

X.COMPANYID,

X.ACTNUMST,

X.BEGINDATE as BEGINDATE,

X.ENDDATE as ENDDATE,

X.YEARBEGBALANCE as YEARDEGBALANCE,

X.YEARBEGBALANCE+X.BEGBALANCE as BEGBALANCE,

X.YEARBEGBALANCE+X.ENDBALANCE as ENDBALANCE,

X.INTERESTONBALANCE as INTERESTONBALANCE,

X.INTERESTONTRANSACTIONS as INTERESONTRANSACTIONS,

X.INTERESTONBALANCE+X.INTERESTONTRANSACTIONS as INTEREST

into AST_INTEREST_TABLE

from

(

select

ก+ @char39+ @Company1 + @char39+ก as COMPANYID,

a.ACTNUMST,

ก+ @char39 + @Datefrom + @char39 +ก as BEGINDATE,

ก+ @char39 + @Dateto + @char39 +ก as ENDDATE,

case when

b.PERDBLNC is null then 0

else b.PERDBLNC

end as YEARBEGBALANCE,

sum

(

case

when (c.DEBITAMTc.CRDTAMNT is not null and c.TRXDATE =ก+ @char39 + @SDatefrom + @char39 +ก and c.TRXDATE =year(ก+ @char39 + @Datefrom + @char39 +ก)

where

a.ACTNUMST>=ก+@char39+@Accountfrom+@char39 +ก

and a.ACTNUMST=ก+ @char39 + @SDatefrom + @char39 +ก and c.TRXDATE =year(ก+ @char39 + @Datefrom + @char39 +ก)

where

a.ACTNUMST>=ก+@char39+@Accountfrom+@char39 +ก

and a.ACTNUMST

Happy querying and customizing! if you want us to help you give us a call 18665280577! help@albaspectrum.com

About The Author

Andrew Karasev is Chief Technology Officer in Alba Spectrum Technologies – USA nationwide Microsoft CRM, Microsoft Great Plains customization company, based in Chicago, Arizona, California, Colorado, Texas, New York, Georgia, Florida, Canada, UK, Australia and having locations in multiple states and internationally , he is Dexterity, SQL, C#.Net, Crystal Reports and Microsoft CRM SDK developer

akarasev@albaspectrum.com

This article was posted on October 03, 2004

by Andrew Karasev

How To Write A Killer Press Release

How To Write A Killer Press Release

by: John Jantsch

One of the primary tools still used by PR professionals to garner media coverage is the press release. Now understand the purpose of a press release is to grab the attention of an editor, not to offer a word for word story to a publication. Most professionals as well as small business owners misunderstand this concept and are therefore frustrated when they can’t seem to make it work for them.

If you understand that the purpose of a press release is to grab attention then you might also begin to realize that there is a bit of an art to writing an effective one.

This art actually begins with proper format. It probably shouldn’t matter how you format a good story but editor after editor has told me that if a press release comes to them and is not properly formatted, it often doesn’t get read. Read that again if you are bit of a maverick. You want to read about your company in the news then you might just have to follow the rules.

Ultimately your story will have to stand on its own but follow this accepted format and you stand a better chance of making that all important first impression.

+ For release timing

The very first thing to appear on your release is the release date or time. If your story is for immediate release say so For Immediate Release. If there is a reason to hold some news or a seasonal deadline say so. For Release Before Halloween. Some background type releases can also carry the Release at Will tag

+ Contact Information

Don’t make it hard for them to get in touch with you. Right under the release info state your name, address, direct phone, and email address under the heading กFor more informationก Remember the real point is to get them to call you.

+ The Headline

90% of all advertising effectiveness rides on the effectiveness of the headline. It is no different for a press release. Most readers will decide whether or not you have anything to say based solely on the grabbing power of your headline. Pull them in quickly. Write 56 attention grabbing headlines and then put your release away for day or so. Come back and see which ones still grab you. It is that important.

+ Dateline

At the start of the body of your release you are expected to provide some useful information. First the date of the release and then the city the release originates from. Put a dash after the city and then start the body of your release. ie: February 18, 2003 Kansas City, Mo Today in history…

+ Double space

Double space the body of your release. This probably goes back to the days when reporters made notes by pencil in the space between the lines but I guess some still do that.

+ First Paragraph

Okay, so now your headline grabbed them. Tell them what you’re going to tell them in the first paragraph. Don’t beat around the bush or try to be cute here. Hit them with your best shot.

+ Quotes and Credentials

Quotes make for interesting reading. Try to find a newspaper story without a quoted source of some sort. Add your own quotes and then add some credentials to the person you attribute the quote to. If itกs you and you’re a master plumber with 25 years of experience, then say so. ‘the flora and fauna was breathtaking,ก said Bill Sphenkle, one of Kansas Cityกs most experienced plumbers.

+ Call to action

If you want them to interview or visit your website to find out more information, then say so. Bill Sphenkle is available for interviews. Just don’t hype your company or product. Nothing gets your release tossed faster.

+ End

At the end add the symbol # # #

There is a free software program that will allow you to write attention getting, perfectly formatted press releases by simply filling in some blanks and answers guided questions. You can download Instant Press Release

http://www.ducttapemarketing.com/InstantPressRelease.htm

Copyright 2004 John Jantsch

About The Author

John Jantsch is a marketing coach, speaker and author. Find out more at http://www.ducttapemarketing.com.

This article was posted on November 06, 2004

by John Jantsch

Microsoft CRM Customization – programming email ac

Microsoft CRM Customization – programming email activity attachment

by: Boris Makushkin

Microsoft CRM is now on the scene and it is increasing its market share, due to Microsoft Business Solutions muscles and marketing strategy. It is tightly integrated with other Microsoft Business Solutions products such as Microsoft Great Plains, Solomon, Navision. Being relatively inexpensive in comparison to competitors, like Siebel, Oracle Microsoft CRM opens you the door for worldwide operations automation. In this small article we would like to give you, software developer, some hints on Microsoft CRM customization.

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 email attachment this is the main discussion topic. We’ll use C#.Net.

In Exchange handler/event sink you create Activity of email type in MS CRM and one of the tasks is transfer the attachment(s) from the body of the incoming email to the attachment(s) in the Activity. You can realize it through direct access to Microsoft CRM DB. Let’s see C# code:

1. First we are getting access to the letter via ExOLEDB:

CDO.Message iMessage = new CDO.MessageClass();

CDO.IBodyPart iPrt;

iMessage.DataSource.Open(bstrURLItem, null, ADODB.ConnectModeEnum.adModeRead,

ADODB.RecordCreateOptionsEnum.adFailIfNotExists, ADODB.RecordOpenOptionsEnum.adOpenSource, กก, กก);

2. Next – we come through the attachment list, get their names and save their bodies into temporary catalogue:

for(int i = 1; i ก;

strXml += กActivity 1ก;

strXml += กก + attachmentNumber + กก;

strXml += กก + emailId.ToString(กBก) + กก;

strXml += กก;

// Create the activity attachment

Guid attachmentId = new Guid(activityAttachment.Create(userAuth, strXml));

log.Debug(กCreate Attachemnt ID: ก + attachmentId.ToString(กBก));

UploadFileToDB(attachmentId, filename, filesize);

return attachmentId;

}

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. Main problem, however is attachment body adding to MS CRM database. Main requirement is – attachment must be encoded as BASE64 stream and its length must be specified correctly together with Nine Type and file name of the file it will be knows as an attachment in activity. Let’s look at the C# code:

public void UploadFileToDB(Guid attachmentId, string filename, long filesize) {

string contentType = กapplication/octetstreamก;

try {

Hashtable mimes = LoadMimeDB(Environment.SystemDirectory + ก/Albaspectrum/ContentType.txtก);

if (mimes != null) {

string tmpContentType = GetMimeType(mimes, filename);

if (tmpContentType != null && !tmpContentType.Equals(กก))

contentType = tmpContentType;

}

byte[] memoryData = new byte[filesize];

FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);

BinaryReader reader = new BinaryReader(fs);

reader.Read(memoryData, 0, (int)filesize);

reader.Close();

fs.Close();

OleDbCommand command = conn.CreateCommand();

command.CommandText = กUPDATE ActivityMimeAttachment SET FileSize = (?), MimeType = (?), FileName = (?), Body = (?) WHERE ActivityMimeAttachmentId = (?)ก;

command.Prepare();

command.Parameters.Add(new OleDbParameter(กFileSizeก, filesize));

command.Parameters.Add(new OleDbParameter(กMimeTypeก, contentType));

command.Parameters.Add(new OleDbParameter(กFileNameก, new FileInfo(filename).Name));

command.Parameters.Add(new OleDbParameter(กBodyก, Convert.ToBase64String(memoryData, 0, (int)filesize)));

command.Parameters.Add(new OleDbParameter(กActivityMimeAttachmentIdก, attachmentId));

log.Debug(กPrepare to upload attachemnt ก + attachmentId.ToString(กBก) + ก in ActivityMimeAttachmentก);

command.ExecuteNonQuery();

memoryData = null;

}

catch (Exception e) {

log.Debug(e.Message + ก

ก + e.StackTrace);

}

}

6. File ContectType.txt is matching list of the files extensions and their mimetype in the following format:

asc application/pgpencrypted Armored Encrypted file (PGP)

asd application/astound Autosave file (Word for Windows)

asm PC ASM File

asn application/astound

etc.

Happy customizing, implementing and modifying! If you want us to do the job give us a call 18665280577! 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, Moscow and Europe and internationally (www.albaspectrum.com), he is Microsoft CRM SDK, C#, VB.Net, SQL, Oracle, Unix developer.

borism@albaspectrum.com

This article was posted on October 24, 2004

by Boris Makushkin

Microsoft CRM Customization: Integration with thir

Microsoft CRM Customization: Integration with third party SQL Application/Database

by: Andrew Karasev

Microsoft CRM – Client Relationship Management package from Microsoft Business Solutions was initially designed to be customizable with Microsoft Visual Studio.Net and one of its programming languages – C#.Net or VB.Net. You can use ADO.Net, Web Service, Transact SQL scripting and stored procedures, deploy such SQL Server tools as Linked Server to all ODBC/OLEDB compliant database, including ORACLE, Sybase, Ingress, DB2, Unidata, Pervasive SQL, Ctree and even Lotus Notes/Domino. In this small article we would like to give you the clue on programming the integration with SQL third party Database.

First – use Microsoft CRM SDK to initiate communication with Microsoft CRM, we have it in C#:

String[] arr1 = coll.AllKeys;

int loop1, loop2;

for (loop1 = 0; loop1 0?1:arr1.Length); loop1++)

{

String[] arr2 = coll.GetValues(arr1[loop1]);

for (loop2 = 0; loop2

Then you use ADO.Net for calling stored procedure with parameters to do the integration job:

try

{

string SQLStatement=กICS_UpdateAccountPrivate กก+

strAccountId +กก , กก + this.TextBoxWorkPerformed.Text +

กก , ก+doubleEncode(System.Double.Parse(this.TextBoxAnnualRevenue.Text))+ก , ก+

intEncode(System.Int32.Parse(this.TextBoxNumberOfEmployees.Text.Replace(ก,ก,กก)))+ก , ก+

doubleEncode(System.Double.Parse(this.TextBoxAverageGrowthRate.Text))+ก , ก+

กกก+this.DropDownListOwnership.SelectedItem.Text +กก , ก+

intEncode(System.Int32.Parse(this.RadioButtonList.SelectedItem.Value))+ก , ก+

intEncode(System.Int32.Parse(this.TextBoxCredit.Text.Replace(ก,ก,กก)))+ก , กก+

this.TextBoxComments.Text+กกก;

System.Data.SqlClient.SqlConnection tmpConnection =

new System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings[กConnectionStringICSก]

);

About The Author

Andrew Karasev is Chief Technology Officer in Alba Spectrum Technologies – USA nationwide Great Plains, Microsoft CRM customization company, based in Chicago, California, Texas, Florida, New York, Georgia, Colorado, Oregon, Washington, Canada, UK, Australia and having locations in multiple states and internationally (www.albaspectrum.com), he is CMA, Great Plains Certified Master, Dexterity, SQL, C#.Net, Crystal Reports and Microsoft CRM SDK developer. You can contact Andrew: 18665280577 andrewk@albaspectrum.com.

akarasev@albaspectrum.com

This article was posted on October 18, 2004

by Andrew Karasev

Microsoft CRM Customization: MS Exchange Transport

Microsoft CRM Customization: MS Exchange Transport SMTP Event Sink

by: Boris Makushkin

Microsoft CRM has variety of customizations options and tools. The official and the most popular is Microsoft CRM SDK: collection of C#.Net and partially VB.Net classes, methods and code samples. Here we would like to give you more complex case, when you call CRM SDK customization from custom MS Exchange event handler – we are improving the functionality of MS Exchange – MS CRM connector.

Imagine the case when you want outgoing email to be captured and placed into CRM, attached to Contact, Account or Lead they should belong to. If this is realized – your salespeople can use any email tool to send their messages, they do not have to do it in CRM or Outlook Client for CRM.

MS Exchange OnSyncSave database event can’t work with Sent folder – it doesn’t fire when message goes to Sent folder. The reason is described here:

PRB: Store Events Do Not Fire on the Outbox or Sent Item Folders

http://support.microsoft.com/default.aspx?scid=kb;enus;Q297274

Please, see SMTP Event Sink example in this article: http://support.microsoft.com/default.aspx?scid=kb;enus;317327. Event handler works OnArrival event:

void ISMTPOnArrival.OnArrival(CDO.IMessage msg, ref CDO.CdoEventStatus EventStatus)

{

log = LogManager.GetLogger(typeof(ShieldsUp));

DOMConfigurator.Configure(new FileInfo(Environment.SystemDirectory + ก/CustomerApp/log.configก));

try {

ProcessMessage(msg);

}

catch (Exception ex) {

log.Debug(ex.Message + ก
ก + ex.StackTrace);

}

finally {

LogManager.Shutdown();

}

}

The class:

// ComVisible enables COM visibility of this class. The default is true.

// Explicitly setting this attribute to true, as shown below, is useful

// if ComVisible is set to false for the namespace and you want the

// classes to be accessible individually.

[ComVisible(true)]

public class ShieldsUp: CDO.ISMTPOnArrival

{

Next the handling works similar to SyncSave handler:

private void ProcessMessage(CDO.IMessage msg)

{

string sFrom;

string sTo;

string sSubject;

string sBody;

string sSensitivity;

try

{

log.Debug(กFiring Up ProcessMessage()ก);

sSubject = msg.Subject;

sBody = msg.TextBody;

sFrom = msg.From;

sTo = msg.To;

if (msg.Fields[กurn:schemas:mailheader:sensitivityก].Value != null)

sSensitivity = msg.Fields[กurn:schemas:mailheader:sensitivityก].Value.ToString();

else

sSensitivity = กNormalก;

log.Debug(กMessage From: ก + sFrom);

log.Debug(กMessage To: ก + sTo);

log.Debug(กSubject: ก + sSubject);

log.Debug(กSensitivity: ก + sSensitivity);

log.Debug(กBody: ก + sBody);

In deployment you should consider the following – the handler will work only in the case of SMTP protocol delivery. If you use Outlook or Outlook Web Access, then delivery uses MAPI and OnArrival doesn’t fire. Please see this article: http://support.microsoft.com/default.aspx?scid=kb;enus;273233

The elegant fix is two SMTP gateways, find it here http://support.microsoft.com/default.aspx?scid=kb;enus;Q288756

About The Author

Boris Makushkin is Lead Developer in Alba Spectrum Technologies – USA nationwide Great Plains, Microsoft CRM customization company, based in Chicago, California, Colorado, Arizona, New York, Texas, Florida, Georgia and having locations in multiple states and internationally (www.albaspectrum.com), he is Microsoft CRM SDK, Transact SQL, C#.Net, Crystal Reports and VB.Net developer. Boris can be reached: 18665280577, borism@albaspectrum.com.

This article was posted on October 14, 2004

by Boris Makushkin

Microsoft Great Plains Integrations – Retail Manag

Microsoft Great Plains Integrations – Retail Management sample

by: Andrew Karasev

Microsoft Business Solutions is emerging as very attractive vendor for midsize companies. The strength of its products is in their cross integration potential. This integration strategy will be the software development direction for this Microsoft subdivision. Meanwhile, as of right now – we have to recommend just to stake on it and deal with custom or inhouse developed integration.

If you are developer who needs some sample code to start with – we are placing Accounts Receivable level integration code – it pulls info from Microsoft RMS and places it into work tables in Great Plains.

Be aware, that Microsoft Great Plains version 7.5 has out of the box integration with Microsoft RMS 1.2, but it is on GL and POP level only. You can’t do check book reconciliation, for example. Currently Microsoft is in decision on who will be coding the integration for Great Plains 8.0 and what the functionality should be. More likely – it will be Nodus Technologies with the integration on SOP and GL level – it will deploy Great Plains Dexterity and MS SQL Server stored procs.

And here is the code, you have to deal with RM10301 and distribution RM, also we recommend insert new customers into RM00101 and RM00102:

Sales Transaction Record

insert into RM10301

(

DOCTYPE,

RMDTYPAL,

RMDNUMWK,

DOCNUMBR,

DOCDESCR,

DOCDATE,

BACHNUMB,

BCHSOURC,

CUSTNMBR,

CUSTNAME,

ADRSCODE,

COSTAMNT,

SLSAMNT,

MISCAMNT,

FRTAMNT,

TAXAMNT,

DOCAMNT,

CASHAMNT,

CBKIDCSH,

CASHDATE,

DCNUMCSH,

CHEKAMNT,

CBKIDCHK,

CBKIDCRD,

CHEKNMBR,

CHEKDATE,

DCNUMCHK,

CRCRDAMT,

DCNUMCRD,

CRCRDNAM,

RCTNCCRD,

CRCARDDT,

TRDISAMT,

ACCTAMNT,

DISCDATE,

DUEDATE,

LSTEDTDT,

LSTUSRED,

GLPOSTDT,

PSTGSTUS,

CURNCYID,

TXENGCLD

)

select

DOCTYPE = (case

when a.Total > 0 then 1

else 7

end),

RMDTYPAL = (case

when a.Total > 0 then 1

else 8

end),

RMDNUMWK = กSMSก + replicate(ก0ก,

13 datalength(convert(varchar(13), a.TransactionNumber))) +

convert(varchar(13), a.TransactionNumber) + convert(varchar(10), a.StoreID),

DOCNUMBR = กSMSก + replicate(ก0ก,

13 datalength(convert(varchar(13), a.TransactionNumber))) +

convert(varchar(13), a.TransactionNumber) + convert(varchar(10), a.StoreID),

DOCDESCR = left(a.ReferenceNumber, 29),

DOCDATE = convert(varchar(10), a.[Time], 101),

BACHNUMB = กSMSก

+ replicate(ก0ก,

2 datalength(convert(varchar(2), a.StoreID))) +

convert(varchar(2), a.StoreID)

+ replicate(ก0ก,

9 datalength(convert(varchar(11), a.BatchNumber))) +

convert(varchar(11), a.BatchNumber),

BCHSOURC = กRM_Salesก,

CUSTNMBR=กCASHก,

CUSTNAME = กCASHก,

ADRSCODE = กPRIMARYก,

COSTAMNT = (case

when isnull((select round(sum(round(Cost * Quantity,2)),2)

from LINKEDSERVER.HQ.dbo.TransactionEntry

where TransactionNumber = a.TransactionNumber and

StoreID = a.StoreID),0) > 0 and a.Total > 0 then

abs(isnull((select round(sum(round(Cost * Quantity,2)),2)

from LINKEDSERVER.HQ.dbo.TransactionEntry

where TransactionNumber = a.TransactionNumber and

StoreID = a.StoreID),0))

when isnull((select round(sum(round(Cost * Quantity,2)),2)

from LINKEDSERVER.HQ.dbo.TransactionEntry

where TransactionNumber = a.TransactionNumber and

StoreID = a.StoreID),0) 0 and

a.StoreID = ก1ก and

not exists (select 1 from RM10301 c

where c.RMDNUMWK = กSMSก + replicate(ก0ก,

13 datalength(convert(varchar(13), a.TransactionNumber))) +

convert(varchar(13), a.TransactionNumber) + convert(varchar(10), a.StoreID) and

c.RMDTYPAL = (case

when a.Total > 0 then 1

else 8

end)) and

not exists (select 1 from RM00401 c

where c.DOCNUMBR = กSMSก + replicate(ก0ก,

13 datalength(convert(varchar(13), a.TransactionNumber))) +

convert(varchar(13), a.TransactionNumber) + convert(varchar(10), a.StoreID) and

c.RMDTYPAL = (case

when a.Total > 0 then 1

else 8

end))

and a.[Time] > ก01/01/2004ก

Happy integrating! if you want us to do the job or use our product give us a call 18665280577! help@albaspectrum.com

About The Author

Andrew Karasev is Chief Technology Officer in Alba Spectrum Technologies – USA nationwide Great Plains, Microsoft CRM, Microsoft RMS customization company, based in Chicago, Arizona, California, Colorado, Texas, Georgia, New York, Florida and having locations in multiple states and internationally (www.albaspectrum.com), he is Dexterity, SQL, C#.Net, Crystal Reports and Microsoft CRM SDK developer.

akarasev@albaspectrum.com

This article was posted on October 11, 2004

by Andrew Karasev

Microsoft CRM Integration: Siebel Email Attachment

Microsoft CRM Integration: Siebel Email Attachments Import C# and MS Transact SQL example

by: Boris Makushkin

Microsoft CRM – CRM answer from Microsoft Business Solutions has aggressive pricing, going down and making it affordable for small companies. We see cases when Microsoft CRM replaces such traditional CRM systems as Siebel. It is not necessary, that clients decided to replace it themselves – they may be victims of their systems – the example: Great Plains had alliance with Siebel several years ago and we saw multiple clients with Great Plains – Siebel tandem. Now Great Plains integrates with MS CRM.

This article is for programmer, who needs data to be migrated from Siebel or other CRM to MS CRM.

Today’s topic is Siebel emails, stored in the files, import into MS CRM database. Each message exists in the form of separate file in the import directory. We will use custom SQL table, created in MS SQL Server 2000:

if exists (select * from dbo.sysobjects where id = object_id(Nก[dbo].[CrmAttachImporter]ก) and OBJECTPROPERTY(id, NกIsUserTableก) = 1)

drop table [dbo].[CrmAttachImporter]

GO

CREATE TABLE [dbo].[CrmAttachImporter] (

[Id] uniqueidentifier ROWGUIDCOL NOT NULL ,

[CrmActivityGuid] [varchar] (50) NOT NULL ,

[MsgFileName] [varchar] (2000) NOT NULL

) ON [PRIMARY]

GO

Comments to this table – its goal is storing MS CRM activity GUID relationship to file name with email attachment (email message), which needs to be attached to the activity. We will store activity GUID in the field CrmActivityGuid and file name in the import directory of the attachment in the MsgFileName field.

Configuration file for our utility will be the following:

provider=SQLOLEDB;Initial Catalog=Albaspectrum;Data Source=MSSQL1;User Id=sa;Password=sa;

data

CrmAttachImporter

CrmActivityGuid

MsgFileName

Here we described MS SQL Server connection string, the path to messagesfiles in the file system, table name, which stores the relations Activity GUID and file names, table column names, required for import procedure

To control import process we will use free logging library for .NET: log4net. You can get it here: http://logging.apache.org/log4net/

Let’s look at the method of potential attachments catalog scanning:

public void scanFolder() {

log = LogManager.GetLogger(typeof(AttachImporter));

DOMConfigurator.Configure(new FileInfo(กlog.configก));

try {

DirectoryInfo dirInfo = new DirectoryInfo(msgFolder);

FileInfo[] files = dirInfo.GetFiles();

Hashtable emails = new Hashtable();

foreach (FileInfo fileInfo in files) {

log.Debug(กAnalizing file: ก + fileInfo.Name);

Guid activityId = GetActivityIdByFileName(fileInfo.Name);

if (! activityId.ToString().Equals(new Guid().ToString())) {

emails.Add(activityId, fileInfo.DirectoryName + @ก\ก + fileInfo.Name);

Console.WriteLine(กMarked for import: ก + fileInfo.Name);

log.Debug(กMarked for import: ก + fileInfo.Name);

}

else {

Console.WriteLine(กNot found in activity import list: ก + fileInfo.Name);

log.Debug(กNot found in activity import list: ก + fileInfo.Name);

}

}

ProcessMessages(emails);

}

catch (Exception e) {

Console.WriteLine(e.Message + ก

ก + e.StackTrace);

}

}

Central place in this method is checking on the relationship existence in the import table for CRM Activity GUID and file name in the import directory:

private Guid GetActivityIdByFileName(string fileName) {

//create the database connection

OleDbConnection conn = new OleDbConnection(connectionString);

conn.Open();

//create the command object and store the sql query

OleDbCommand command = conn.CreateCommand();

command.CommandText = กSELECT ก + activityGuidColumn + ก, ก + msgFileNameColumn + ก FROM ก + tableName + ก WHERE UPPER(LTRIM(RTRIM(ก + msgFileNameColumn + ก))) = UPPER(LTRIM(RTRIM(?)))ก;

log.Debug(กPreview checking SQL query: ก + command.CommandText);

log.Debug(กUsing file name: ก + fileName);

command.Parameters.Add(new OleDbParameter(msgFileNameColumn, fileName));

//create the datareader object to connect to table

OleDbDataReader reader = command.ExecuteReader();

if (reader.Read()) {

Guid activityGuid = new Guid(reader.GetString(0));

reader.Close();

conn.Close();

return activityGuid;

}

else {

reader.Close();

conn.Close();

return new Guid();

}

}

Importing messages cache is transferred as a parameter to the method, which does attachment import into MS CRM:

private void ProcessMessages(Hashtable emails)

{

try

{

log.Debug(กStart importing processก);

CRMConnector crmConnector = new CRMConnector();

// Connect to CRM DB

crmConnector.SetCrmConfigPath(Environment.SystemDirectory + ก/Albaspectrum/MSCRMGateway.xmlก);

crmConnector.SetCrmContentType(Environment.SystemDirectory + ก/Albaspectrum/ContentType.txtก);

crmConnector.Connect(log);

if (emails != null) {

ICollection keys = emails.Keys;

int attCounter = 0;

foreach (Guid o in keys) {

string attName = (string)(emails[o]);

crmConnector.AddAttachmentToActivity(o, attName, (new FileInfo(attName)).Length, attCounter);

attCounter++;

}

}

crmConnector.Close();

}

catch (Exception ex)

{

log.Debug(ex.Message + ก
ก + ex.StackTrace);

}

}

All the required classes for working with MS CRM Activity are stored in MSCRMGateway library and described in these articles:

http://www.albaspectrum.com/Customizations_Whitepapers/Dexterity_SQL_VBA_Crystal/MSCRMCUstomizationEmailAttachment.htm

http://www.albaspectrum.com/Customizations_Whitepapers/Dexterity_SQL_VBA_Crystal/MSCRMCUstomizationClosedActivity.htm

Happy converting and importing! If you would like us to do the job, give as a call 1630.961.5918 or 1866.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, serving Chicago, California, Arizona, Colorado, New York, Texas, Georgia, Florida, Canada, Australia, UK, Russia, Europe and internationally ( http://www.albaspectrum.com ), he is Microsoft CRM SDK, Navision, C#, VB.Net, SQL, Oracle, Unix developer.

BorisM@albaspectrum.com

This article was posted on December 23, 2004

by Boris Makushkin

The New Business Model

The New Business Model

by: Romain Marucchi

In this new era of information, business promote the new (now) standardized and stereotyped model of the cyber กdoortodoorก salesman, armed with lap top, cell phone, palm pilot; ready day and night for a next good war against the next competitorกs web page displayed. In this new world of กbrief cased guinea pigsก totally กoverloadedก by the quantity of digital information, where technology is the weapon against the neighbor, the good old กdollar buckก is the only reward; rewarded and quantified to the best กoptimizedก, กsuited and tiedก digital business slave.

a = (1(small business) + 2(good idea) + 3(great potential) + 4 (determination));

factorX = กno moneyก;

print (a + factorX);

>> [processor fault]

Where on this dynamic LCD/CRT two dimensional world that is the modern computer world of today, a กpromisingก small business can go without the factor x? Without a website, who are you? Without a website how you can sell your products? Many solutions exists out there, in the so called ‘the free worldก, but which one is reliable, which one is really there to help your situation? Which one really think of you as a business in this kind of situation?

I personally try them all, I was also even at the point to register to the กseems to be miraculousก five letters starting with a กYก; merchant solution then… Wait, stop, backup, what about one solution that provide me everything that I need: Web hosting, Merchant Tools, Catalog Manager, Order Management System, Business Email, DNS Hosting, Database Service, Ftp Account and place that can index my website and the products it contains, for free…? is it possible? Is it the กnew business modelก that I am looking for? Or I still need to struggle against the stereotyped description as above during weeks and a lot of PDF printed forms? to get…whatever?

Then it all comes together: wOOmba.NET, what about providing one free internet solution that offer everything a small business need to กstart upก on the internet, then I start rumbling with my favorite type of กIBM lemmingsก to give to thousands of people around the world the opportunity to have access to the proper tools in order to save time and money, and be successful with their small business.

Today wOOmba is a constant growing community born from theses little enterprises that think like us that the internet should be a กfree and open mindedก business tools for companies. Sometimes the best idea don’t come from giants, but from simple people that sees things differently, and grouped together make something gigantic…

About The Author

Romain Marucchi

CEO wOOmba.net

romain@woomba.net

This article was posted on December 18, 2004

by Romain Marucchi

How to get non Reciprocal Links

How to get non Reciprocal Links

by: Matt Colyer

In this article we will look at how to get non reciprocal links.
Webmasters have become paranoid with link popularity therefor making it the most popular SEO techniques that is used on the web today. Why should you be worried about link popularity? Because it is one of the most important things that search engines use to rank web sites. Search engines have begun to see a problem with this because webmasters are trading links left and right. So now they put less importance on reciprocal links. Below you will see how easy it is to get non reciprocal.
1) You should get your site listed in both Yahoo! and the DMOZ because it can boost the rank of a site much more than a few links from an other site. It can be hard to get listed in both Yahoo! and the DMOZ because they only accept sites that offer original content and sites that are believed to be useful to Internet surfers. To get in Yahoo! it may cost you from free to 299 dollars, it depends on what category the site belongs to. The DMOZ is free matter what category your site belongs to.
2) Write articles to be published on other sites, like this article here you are reading. Use your expertise to write useful articles in your subject/market to be published. You can submit to Yahoo! Groups and articlecity.com. The sites that include your article will also include a resource box with a link back to your site.
3) Get your site listed in directories that are related to your siteกs market. This is very useful at not only boasting your ranking in the search engines, but getting you targeted traffic. If you own a site thatกs about games search with game resources or game directory. Letกs say your site is about dogs search with animal links or dog directory. You can also try…
Add site + your keyword/market

Add URL + your keyword/market

Submit URL + your keyword/market

Suggest URL + your keyword/market

Your Region + Add url/market

your keywords + กdirectory/market
4) Create a great content site, if your site has great content or something that no one else offers you will find over time people will link to you because they feel that you have great content or service(s). It takes a lot of time to get links from other web sites this way, but it is well worth the time. You should write artless that are related to your siteกs market, if you are not that great at writing articles or not sure where to start have a look at articlecity.com to get articles that you can publish on your site.
5) Put your signature at the end of each of your posts at forums. Join forums that are related to your siteกs market and post about subjects that you know about with your signature at the end of the message. Some forums allow this, but not all do allow this, so you should make sure itกs allowed by checking the web siteกs rules or the term of services that you have to agree to. Also don’t go around spamming the forums with your links because this WILL make you hated more than you are liked and will make visitors not trust your site.

About The Author

Matt Colyer is the owner of the Marhen.com Network which includes www.linkexchangeit.com and is a parttime SEO. He also is a php, CGI and ASP developer.

This article was posted on July 12, 2004

by Matt Colyer

Microsoft CRM Programming Secrets – tips for devel

Microsoft CRM Programming Secrets – tips for developer

by: Andrew Karasev

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

strPartiesXml += กก;

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

strPartiesXml += กก;

strPartiesXml += กก;

strPartiesXml += กก;

log.Debug(strPartiesXml);

// Create the email 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();

}

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 + ก

ก + e.StackTrace);

}

}

Happy customizing! if you want us to do the job give us a call 18665280577! help@albaspectrum.com

About The Author

Andrew Karasev is Chief Technology Officer in Alba Spectrum Technologies – USA nationwide Microsoft CRM, Microsoft Great Plains customization company, based in Chicago, California, Colorado, Texas, New York, Georgia and Florida, Canada, UK, Australia and having locations in multiple states and internationally (www.albaspectrum.com), he is Dexterity, SQL, C#.Net, Crystal Reports and Microsoft CRM SDK developer.

akarasev@albaspectrum.com

This article was posted on September 11, 2004

by Andrew Karasev