Microsoft CRM Customization

Microsoft CRM customization techniques are very diversified and based on the whole spectrum of recent Microsoft technologies. The main terms you should know are: Microsoft CRM SDK 1.2 and Visual Studio.Net 2003. And of course you should be familiar with all the legacy internet technologies, such as HTML, XML, XSLT, JavaScript and be good C#/VB/Net developer.

If you are developer who is asked: how do we customize Microsoft CRM – read this and you will have the clues on where to look further.

1. Microsoft CRM SDK – this is software development kit with C# and partly VB.net examples – it is supported by Microsoft Business Solutions technical support. It is all web services based calls, if you are C# .NET developer – you are excellently positioned to do this type of customizations. This is the preferred customization scenarios and this should be easily upgradeable customization.

2. Legacy SQL Data integration. This is also easy and safe. If you have SQL database, sitting on the same or linked SQL Server – you can create ASPX .Net application and simply integrate it into CRM. You can place it on the navigation bar or menu in isv.config – please refer to MS CRM SDK

3. Legacy ASP integration – this is somewhat more sophisticated. You have to deploy HTTP handler to be a middle party between CRM which is .Net based and ASP which is legacy IIS. The trick is – you have to have INI file with security settings to penetrate into MS CRM with proper credentials, calling web service.

4. Microsoft Exchange Programming. Microsoft CRM has Exchange connector – which moves CRM incoming email to MS if it has GUID in its subject. You can alter this logic (for instance - move email to CRM if it doesn’t have GUID but it is from the sender who is contact or account in MS CRM). Refer to MS Exchange SDK onsyncsave event handling. Then simply apply some MS CRM SDK programming

5. Direct SQL touch – in #4 above I described you the scenario with MS Exchange handlers – this would be ideal world if MS CRM SDK does the job. But – in real world this is not always true – you have to do direct flags correction in CRM database (like making Activity closed, moving email attachments/octet streams, etc). This is not supported by MBS technical support – but you can rescue to this technique if you have to make job done.

6. MS CRM Customization tool – you can feel free to use this – this is rather end-user tool and we don’t describe it here – read the manual. We’ve described above the options to use when this tool doesn’t do the job

Happy customizing! if you want us to do the job - give us a call 1-866-528-0577! 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, Brazil, Mexico (www.albaspectrum.com), he is Dexterity, SQL, C#.Net, Crystal Reports and Microsoft CRM SDK developer.

akarasev@albaspectrum.com

Microsoft CRM – Typical Customizations

Microsoft CRM was designed to be easily customizable. Microsoft CRM Software Development Kit (MS CRM SDK) which you can download from Microsoft website contains descriptions of the objects or classes, exposed for customization. It has sample code in C# and partially in VB.Net. In Visual Studio.Net you can analyze all the classes, used by Microsoft developers to create MS CRM - you will discover that most of them are not documented in MS CRM SDK. Microsoft will not support your customization if you use undocumented class or do direct SQL access to CRM database.

Let us describe you - programmer, software developer typical cases of MS CRM Customizations.

1. Integration with SQL Server application. If you have legacy system on MS SQL Server - let's say you are transportation company and have in-house developed cargo tracking database. Now in MS CRM you want lookup the shipments for the customer (or account in CRM). This is SDK programming and calling SQL stored proc to retrieve cargo info. Instead of SQL Server you can have other database (ORACLE, MS Access, PervasiveSQL to name a few) - you can access multiple Database platforms via ADO.Net connection from your .Net application, which is easily integrated into MS CRM Account screen.

2. Email capturing in MS CRM. You have customer with email Bill@customer.com. Now you want all the emails that you receive from customer.com domain to be attached to Bill who is account in CRM. This is more difficult customization - you have to create MS CRM SDK web service, that one will be creating email activity and call it from COM+ application - Microsoft Exchange event handler (ONSYNCSAVE database event sink). This example maybe complicated with the following requirement. Imagine that Bill, instead of answering to your email (sent from CRM and processed by CRM-Exchange connector) sends you new message from MS Outlook. Then this email will not follow into MS CRM (because it doesn't have GUID in the header and so is ignored by CRM Exchange connector). If you want to capture these emails - you have to do it in Microsoft Exchange event sink. There maybe scenario when you want to capture and analyze in the sink all the outgoing emails - this is even more complex - y!

ou have to place the sink on transport event.

3. ASP Application integration. You have legacy ASP application, where you capture orders from your customers and you want these orders be transferred to the CRM as activity. Here you understand that ASP doesn't deploy Active Directory security - and the best way is to create HTTP handler and call it from your ASP page. This HTTP handler in turn will call MS CRM SDK web service with predefined (web.config) Active Directory credentials.

Some cautions. Never create your custom SQL objects (like stored procedure, SQL view, table) in MS CRM database. Instead, create your own database and place your objects there. When you see the first caution - you will never try to alter existing CRM objects, like adding new field to the table.

Happy customizing! if you want us to do the job - give us a call 1-866-528-0577! help@albaspectrum.com

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, New York, Florida, Georgia, Minnesota, Oregon, Arizona, Canada, UK, Australia and having locations in multiple states and internationally (www.albaspectrum.com), he is Microsoft CRM SDK, Great Plains Dexterity, SQL, C#/VB.Net and Crystal Reports developer.


akarasev@albaspectrum.com

Microsoft CRM Selection

Microsoft CRM is recent (2001) CRM answer from Microsoft and attempt top get market share from traditional vendors: Siebel, Oracle, Onyx. 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).

We would like you to give you Microsoft CRM selection advise, based on our MS CRM consulting practice, going back to its inception in 1999. This article is written in FAQ style for beginner level

1. What is your industry – how strange it may look – close to 40% of our clients or so-called orphan clients – who needs help with Microsoft CRM customization are freight forwarding, transportation companies, who needs either improvement in Exchange-CRM connector or MS CRM integration with their freight forwarding system, where they would like to see on the fly resent shipment info. And also to mention freight forwarding companies are usually large (more than 50 CRM users)

2. How comfortable you are with Microsoft technology in-house support – The old-days idea of Apple computer was to make computer absolutely intuitive and working for housewife. Now we know that this is not realized so far. If you compare MS CRM with Siebel – you will see that MS CRM requires y0u to have Microsoft Certified people in staff. Everyone knows that Microsoft is “so innovative” that each product requires daily service packs and patches

3. Do you have Great Plains, Solomon or Navision – CRM is usually integrated with ERP system and if you are looking at MS CRM – you should benefit if you have ERP from Microsoft Business Solutions (Great Plains, Solomon, Navision, Axapta or Small Business Manager - SBM)

4. Operating System Philosophy - Microsoft likes clients who have no UNIX/LINUX/IBM/Apple etc inclination and staked on Microsoft Windows 2003/2000/XP/Longhorn, preferably staying on Intel platform (No AMD Athlon 64)

Have fun in selection and decision. We are here to help you: 1-866-528-0577

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, Colorado, California, Texas, New York, Georgia and 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

Microsoft CRM Programming Techniques – overview for developer

Microsoft CRM is the CRM answer from Microsoft and it will have all the Microsoft Business Solutions muscles behind.

If you are developer who is asked: how do we customize Microsoft CRM – read this and you will have the clues on where to look further.

1. Microsoft CRM SDK – this is software development kit with C# and partly VB.net examples – it is supported by Microsoft Business Solutions technical support. It is all web services based calls, if you are C# .NET developer – you are excellently positioned to do this type of customizations. This is the preferred customization scenarios and this should be easily upgradeable customization.

2. Legacy SQL Data integration. This is also easy and safe. If you have SQL database, sitting on the same or linked SQL Server – you can create ASPX .Net application and simply integrate it into CRM. You can place it on the navigation bar or menu in isv.config – please refer to MS CRM SDK

3. Legacy ASP integration – this is somewhat more sophisticated. You have to deploy HTTP handler to be a middle party between CRM which is .Net based and ASP which is legacy IIS. The trick is – you have to have INI file with security settings to penetrate into MS CRM with proper credentials, calling web service.

4. Microsoft Exchange Programming. Microsoft CRM has Exchange connector – which moves CRM incoming email to MS if it has GUID in its subject. You can alter this logic (for instance - move email to CRM if it doesn’t have GUID but it is from the sender who is contact or account in MS CRM). Refer to MS Exchange SDK onsyncsave event handling. Then simply apply some MS CRM SDK programming

5. Direct SQL touch – in #4 above I described you the scenario with MS Exchange handlers – this would be ideal world if MS CRM SDK does the job. But – in real world this is not always true – you have to do direct flags correction in CRM database (like making Activity closed, moving email attachments/octet streams, etc). This is not supported by MBS technical support – but you can rescue to this technique if you have to make job done.

6. MS CRM Customization tool – you can feel free to use this – this is rather end-user tool and we don’t describe it here – read the manual. We’ve described above the options to use when this tool doesn’t do the job

Happy customizing! if you want us to do the job - give us a call 1-866-528-0577! 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

Microsoft CRM Programming Secrets – tips for developer

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

}

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 1-866-528-0577! help@albaspectrum.com

bout 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

Microsoft CRM or Siebel

Siebel is traditional CRM market leader, however and mostly due to recession 200-2003, Siebel lost sizable portion of CRM market to new tiger, such as Microsoft CRM. Microsoft CRM s recent (2001) CRM answer from Microsoft and attempt top get market share from traditional vendors: Siebel, Oracle, Onyx. 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).

We would like to give you Microsoft CRM selection advise, based on our MS CRM consulting practice, going back to its inception in 1999. This article is written in FAQ style for beginner level

1. What is your industry – how strange it may look – close to 40% of our clients or so-called orphan clients – who needs help with Microsoft CRM customization are freight forwarding, transportation companies, who needs either improvement in Exchange-CRM connector or MS CRM integration with their freight forwarding system, where they would like to see on the fly resent shipment info. And also to mention freight forwarding companies are usually large (more than 50 CRM users)

2. How comfortable you are with Microsoft technology in-house support – The old-days idea of Apple computer was to make computer absolutely intuitive and working for housewife. Now we know that this is not realized so far. If you compare MS CRM with Siebel – you will see that MS CRM requires y0u to have Microsoft Certified people in staff. Everyone knows that Microsoft is “so innovative” that each product requires daily service packs and patches

3. Do you have Great Plains, Solomon or Navision – CRM is usually integrated with ERP system and if you are looking at MS CRM – you should benefit if you have ERP from Microsoft Business Solutions (Great Plains, Solomon, Navision, Axapta or Small Business Manager - SBM)

4. Operating System Philosophy - Microsoft likes clients who have no UNIX/LINUX/IBM/Apple etc inclination and staked on Microsoft Windows 2003/2000/XP/Longhorn, preferably staying on Intel platform (No AMD Athlon 64)

Have fun in selection and decision. We are here to help you: 1-866-528-0577

About The Author

Andrew Karasev is Chief Technology Officer in Alba Spectrum Technologies – USA nationwide Microsoft CRM, Microsoft Great Plains customization company, with offices in Chicago, Phoenix, Los Angeles. San Francisco, San Diego, New York, Atlanta, Denver, Miami, Toronto, Montreal, Madrid, Moscow (www.albaspectrum.com), he is Dexterity, SQL, C#.Net, Crystal Reports and Microsoft CRM SDK developer.


akarasev@albaspectrum.com


Microsoft CRM Modification – overview for IT specialist

Microsoft CRM is now on the scene and it is increasing its market share, due to the Microsoft Business Solutions muscles and marketing strategy. It is tightly integrated with other Microsoft Business Solutions products such as Microsoft Great Plains, Solomon, Navision.

If you are programmer or database administrator who is asked: how do we modify Microsoft CRM – read this article and you will have the clues for further research.

1. Microsoft CRM SDK – this is software development kit with C# and partly VB.net code samples – it is supported by Microsoft Business Solutions technical support. It is based on web service calls, if you are C# .NET developer – you are excellently positioned to do this type of customizations. This is the preferred modification scenario and this should be easily upgradeable customization. VB.Net examples will be available soon.

2. Legacy SQL Data integration. This is also easy and safe. If you have SQL database, sitting on the same or linked SQL Server – you can create ASPX .Net application and simply integrate it into CRM. You can place it on the navigation bar or menu in isv.config – please refer to MS CRM SDK

3. Legacy ASP integration – this is somewhat more sophisticated. You have to deploy HTTP handler to be a middle party between CRM which is .Net based and ASP which is legacy IIS. The trick is – you have to have INI file with security settings to penetrate into MS CRM with proper credentials, calling web service.

4. Microsoft Exchange Programming. Microsoft CRM has Exchange connector – which moves CRM incoming email to MS if it has GUID in its subject. You can alter this logic (for instance - move email to CRM if it doesn’t have GUID but it is from the sender who is contact or account in MS CRM). Refer to MS Exchange SDK onsyncsave event handling. Then simply apply some MS CRM SDK programming - you need some COM+ objects creation and VB programming experience.

5. Direct SQL touch – in #4 above I described you the scenario with MS Exchange handlers – this would be ideal world if MS CRM SDK does the job. But – in real world this is not always true – you have to do direct flags correction in CRM database (like making Activity closed, moving email attachments/octet streams, etc). This is not supported by MBS technical support – but you can rescue to this technique if you have to get job done.

6. MS CRM Customization tool – this is rather end-user tool and we don’t describe it here – read the manual. We’ve described above the options to use when this tool doesn’t do the job

7. Crystal Reports - feel free to create Crystal report - tables and views structure is self explanatory. Try to avoid the temptation to create your own SQL view or stored procedure in MS CRM database, instead - create custom database and place your view and stored proc in it.

Happy modifying! If you want us to do the job - give us a call 1-866-528-0577! 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, Boston, San Francisco, Los Angeles, Houston, Atlanta, and Miami and having locations in multiple states and internationally (www.albaspectrum.com), he is Dexterity, SQL, VB/C#.Net, Crystal Reports and Microsoft CRM SDK developer.


akarasev@albaspectrum.com

Microsoft CRM Implementation & Remote Support – overview for V.P. IT

Microsoft CRM is now on the scene and it is increasing its market share, due to the 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.

We would like to give you pluses and minuses of Microsoft CRM.

1. Web and MS Outlook based client - this means that you don't need additional installations or training - everyone is using Outlook if you are on Windows XP/2000/2003

2. SQL Server database - just to mention

3. Integration with Microsoft Exchange 2003/2000 - this means that replies to CRM originated emails will be captured and store in CRM as activities for the Contact, Account or Lead.

4. Remote Support - I would say - this would be in the nature of MS CRM - you host it's database in your headquarter and users will connect to it worldwide via Internet Explorer

5. Integration with other MBS products - currently it has integration interface with Microsoft Great Plains

6. Microsoft technologies dependence - yes, this is true and maybe considered as minus, it doesn't work with Netscape or Mozilla browser.

7. New Product - it is relatively new on the market and may not have industry specific features yet

Also if you are considering some customization scenarios, we would suggest you to review the options below:

1. Microsoft CRM SDK – this is software development kit with C# and partly VB.net code samples – it is supported by Microsoft Business Solutions technical support. It is based on web service calls, if you are C# .NET developer – you are excellently positioned to do this type of customizations. This is the preferred modification scenario and this should be easily upgradeable customization. VB.Net examples will be available soon.

2. Legacy SQL Data integration. This is also easy and safe. If you have SQL database, sitting on the same or linked SQL Server – you can create ASPX .Net application and simply integrate it into CRM. You can place it on the navigation bar or menu in isv.config – please refer to MS CRM SDK

3. Legacy ASP integration – this is somewhat more sophisticated. You have to deploy HTTP handler to be a middle party between CRM which is .Net based and ASP which is legacy IIS. The trick is – you have to have INI file with security settings to penetrate into MS CRM with proper credentials, calling web service.

4. Microsoft Exchange Programming. Microsoft CRM has Exchange connector – which moves CRM incoming email to MS if it has GUID in its subject. You can alter this logic (for instance - move email to CRM if it doesn’t have GUID but it is from the sender who is contact or account in MS CRM). Refer to MS Exchange SDK onsyncsave event handling. Then simply apply some MS CRM SDK programming - you need some COM+ objects creation and VB programming experience.

5. Direct SQL touch – in #4 above I described you the scenario with MS Exchange handlers – this would be ideal world if MS CRM SDK does the job. But – in real world this is not always true – you have to do direct flags correction in CRM database (like making Activity closed, moving email attachments/octet streams, etc). This is not supported by MBS technical support – but you can rescue to this technique if you have to get job done.

6. MS CRM Customization tool – this is rather end-user tool and we don’t describe it here – read the manual. We’ve described above the options to use when this tool doesn’t do the job

7. Crystal Reports - feel free to create Crystal report - tables and views structure is self explanatory. Try to avoid the temptation to create your own SQL view or stored procedure in MS CRM database, instead - create custom database and place your view and stored proc in it.

Happy selection, implementation and modification! If you want us to do the job - give us a call 1-866-528-0577! 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, Boston, San Francisco, San Diego, Los Angeles, Houston, Dallas, Atlanta, and Miami and having locations in multiple states and internationally (www.albaspectrum.com), he is Dexterity, SQL, VB/C#.Net, Crystal Reports and Microsoft CRM SDK developer.


akarasev@albaspectrum.com


Microsoft CRM Development: SDK, C#, SQL, Exchange, Integration, Crystal Reports overview for programmer

Microsoft CRM is new player on the CRM software market. The whole conception behind CRM seems to be different. In case of traditional CRM software (Siebel, Oracle) - the application was designed with platform independence in mind. Microsoft CRM is dedicated to Microsoft technology and so deploys all the Microsoft tools: Windows Active Directory, Microsoft Exchange 2003/2000, SQL Server, Crystal Reports Enterprise, Biztalk server, Microsoft Outlook, Internet Explorer, Microsoft Great Plains as backend, etc.

If you are software developer, database administrator or web designer who is asked: how do we customize Microsoft CRM we are giving you directions in this article.

1. Microsoft CRM SDK this is software development kit with C# and partly VB.net code samples it is supported by Microsoft Business Solutions technical support. It is based on web service calls, if you are C# .NET developer you are excellently positioned to do this type of customizations. This is the preferred modification scenario and this should be easily upgradeable customization. VB.Net examples will be available soon.

2. Legacy SQL Data integration. This is also easy and safe. If you have SQL database, sitting on the same or linked SQL Server you can create ASPX .Net application and simply integrate it into CRM. You can place it on the navigation bar or menu in isv.config please refer to MS CRM SDK

3. Legacy ASP integration this is somewhat more sophisticated. You have to deploy HTTP handler to be a middle party between CRM which is .Net based and ASP which is legacy IIS. The trick is you have to have INI file with security settings to penetrate into MS CRM with proper credentials, calling web service.

4. Microsoft Exchange Programming. Microsoft CRM has Exchange connector which moves CRM incoming email to MS if it has GUID in its subject. You can alter this logic (for instance - move email to CRM if it doesnt have GUID but it is from the sender who is contact or account in MS CRM). Refer to MS Exchange SDK onsyncsave event handling. Then simply apply some MS CRM SDK programming - you need some COM+ objects creation and VB programming experience.

5. Direct SQL touch in #4 above I described you the scenario with MS Exchange handlers this would be ideal world if MS CRM SDK does the job. But in real world this is not always true you have to do direct flags correction in CRM database (like making Activity closed, moving email attachments/octet streams, etc). This is not supported by MBS technical support but you can rescue to this technique if you have to get job done.

6. MS CRM Customization tool this is rather end-user tool and we dont describe it here read the manual. Weve described above the options to use when this tool doesnt do the job

7. Crystal Reports - feel free to create Crystal report - tables and views structure is self explanatory. Try to avoid the temptation to create your own SQL view or stored procedure in MS CRM database, instead - create custom database and place your view and stored proc in it.

Happy customizing, modifying and developing! If you want us to do the job - give us a call 1-866-528-0577! 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, Boston, San Francisco, Los Angeles, Houston, Atlanta, and Miami and having locations in multiple states and internationally (www.albaspectrum.com), he is Dexterity, SQL, VB/C#.Net, Crystal Reports and Microsoft CRM SDK developer.


akarasev@albaspectrum.com

Microsoft CRM Customization secrets – second edition

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

}

Our credits to Anna Osborn (so obviously small pocket aquarium goes to her – smile!), she let us know how to close MS CRM Activity:

//creates the activity

strActivityId = oActivity.Create(userAuth, strXml, activityPartyXml);


//closes it as long as the relevant fields are complete oActivity.Close(userAuth, strActivityId, -1);

But in any case whatever you find below could help you to do whatever CRM SDK can’t.

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 1-866-528-0577! 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

Microsoft CRM Customization: MS Exchange Transport SMTP Event Sink

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;en-us;Q297274

Please, see SMTP Event Sink example in this article: http://support.microsoft.com/default.aspx?scid=kb;en-us;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;en-us;273233

The elegant fix is two SMTP gateways, find it here http://support.microsoft.com/default.aspx?scid=kb;en-us;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: 1-866-528-0577, borism@albaspectrum.com.

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

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 < arr2.Length; loop2++)

{

strAccountId = arr2[loop2].Replace("}",null);

strAccountId = strAccountId.Replace("{",null);

}

}


if (Page.IsPostBack==false)

{

// Server should be set with the name of the platform Web server

string Server = ConfigurationSettings.AppSettings["ServerName"];


// VirtualDirectory should be set with the name of the Microsoft

// CRM Virtual Directory on the platform Web server

string VirtualDirectory = "mscrmservices";

string strDir = "http://" + Server + "/" + VirtualDirectory + "/";


// BizUser proxy object

Microsoft.CRM.Proxy.BizUser oBizUser = new Microsoft.CRM.Proxy.BizUser ();

oBizUser.Credentials = System.Net.CredentialCache.DefaultCredentials;

oBizUser.Url = strDir + "BizUser.srf";


// CRMAccount proxy object

Microsoft.CRM.Proxy.CRMAccount account = new Microsoft.CRM.Proxy.CRMAccount ();

account.Credentials = System.Net.CredentialCache.DefaultCredentials;

account.Url = strDir + "CRMAccount.srf";

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: 1-866-528-0577 andrewk@albaspectrum.com.


akarasev@albaspectrum.com

Microsoft CRM Customization – programming email activity attachment

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/octet-stream";


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 mime-type in the following format:

asc application/pgp-encrypted 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 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, Moscow and Europe and internationally (www.albaspectrum.com), he is Microsoft CRM SDK, C#, VB.Net, SQL, Oracle, Unix developer.


borism@albaspectrum.com

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

Microsoft CRM Customization - processing in/out-going email messages

We would like to give you several situations, when you may need custom development and programming to improve Microsoft CRM functionality. This overview is for programmer, software developer, IT specialist, database administrator.

Microsoft CRM, the CRM application from Microsoft Business Solutions utilizes almost all the recent Microsoft technologies: .Net (it is actually written in C#.Net with HTML and Javascript at the web client side plus has Microsoft CRM SDK with C# and partially VB.Net samples), Microsoft SQL Server, Microsoft Exchange 2003/2000 and others. Now to give you brief review from the workflow and messages - you can send email directly from Account, Contact or Lead and it will be processed by Microsoft CRM-Exchange connector. This email will have GUID in the message header. When addressee answers the email - it will be processed by the connector - it will recognize the GUID and will find the original activity and will attach this email as closed activity to the original object: contact, account or lead. This is very nice feature, but in the real world you may have these situations:

1. CRM user will not use CRM interface and will send email from his/her Outlook. Addressee will receive and respond and these emails will not be handled by Microsoft CRM-Exchange connector. They will not have GUID and connector has no idea on what to do with them.

2. Imagine, that you have Account Best Corporation, with contact person John john@bestcorporation.com. Now new person in Best Corporation, Susan sends you message from susan@bestcorporation.com - and her email will not be connected to your Best Corporation account, because this email doesn't have GUID and it also doesn't have matching email in the contact person. So - it is probably nice to catch emails by domain name as well, say - all the emails, coming from www.bestcorporation.com should be attached to Best Corporation account.

3. Now - your sales rep initiated the first email to the client from Microsoft CRM and got response, transferred back into CRM account. Then he occasionally replied on the reply from outlook - this reply, having GUID will be replied back and not transferred into MS CRM, because MS Exchange connector "thinks" that this message was already replied by the first reply.

4. To decrease the possibility that users will use outlook to send new messages and answer the messages from there - you would probably like the idea to delete them from MS Exchange database when they are transferred to the CRM. In this case they will not be seen in MS Outlook (We are not talking about Microsoft CRM Outlook client, where you actually see CRM data and objects)

If you are programmer or software developer - you can actually program these advancements and we'll give you the direction.

This technique is COM+ applications, registered as Microsoft Exchange sinks or handlers. You can use VisualStudio.Net, but you will not have debugging available, because these applications will work as event handlers. Microsoft Exchange allows you to alter it's logic in the events, exposed for custom handling. Incoming emails should be handled, when ONSYNCSAVE Microsoft Exchange Database event is fired before the commitment. You use Microsoft CRM SDK to create the email activity. You should use direct SQL update to flag the activity as closed (however not recommended by Microsoft - but Microsoft CRM SDK doesn't have the method to close the activity - so you really don't have an option from SDK side). Outgoing emails should be handled with so-called transport events firing, which is more complex and less documented part of Microsoft Exchange SDK.

Happy customizing! if you want us to do the job - give us a call 1-866-528-0577! help@albaspectrum.com

About The Author

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


akarasev@albaspectrum.com