Wednesday, December 30, 2009

Developing Your CRM/xRM Applications (Part - I)

There are THREE common methods to use CRM SDK in our extension projects. These are
  1. using CRM web reference, 
  2. using sdk assemblies files, and 
  3. using third-party tools. Each method has its own pros and cons. 

Using CRM web reference in extension project is very easy for implementation. All you need to do is just add web reference. But, if you have 300+ custom entities in your project, there will be some performance issues and memory leak problems occur in application development.

Using sdk assemblies files is good for application performance and stability. But, if you have many custom entities in your project, it will be a nightmare for all developers to do coding using dynamics entity approach.

The last method, using  third-party tools, will help you to a lot in your project implementation. They can provide easy way to implement dynamics entity approach  in your project. But, you have to spend a lot of money on license fees to use those third-party tools.

According to my experience, the second method is the best way for developing xRM applications. But you have to find out your own way to:
  1. generate entity wrapper class automatically
  2. convert wrapper class to dynamic entity, and
  3. implement library programs that support CRM SDK operations
How To Generate CRM Entity Wrapper Class Automatically

Today, I will show you a way to generate entity wrapper class using CRM Development Toolkit.

Software Requirements

1. VS .NET 2008 and .NET Framework 3.5 SP1
2. MS CRM 4.0 (either 32bit or 64bit)

Installation Steps

* Install VS 2008 and .NET Framework 3.5 SP1
* Install MS CRM 4.0 (either 32bit or 64bit)
* Install StyleCop V

Please do not forget to choose “MSBuild Integration Files” so that you can avoid following error message:

* Install CRM Explorer (Please refer to page 10 from "Customizing CRM by Using the Microsoft Dynamics CRM Developer Toolkit.pdf" for more detail)

Configuring CRM Solution Framework

1. The CRM Solution Framework is a suite of Visual Studio C# projects that are coupled with CRM Entity customizations and wrapped with extensible MSBuild–based developer builds and daily builds. The Framework contains several “pre-canned” projects for the typical tasks that are required of developers when undertaking most Enterprise-level CRM projects. Several of these projects have an inheritance model that affords simple and intuitive augmentation, which can significantly reduce the time required to “jump start” development of new projects.

2. Install CRM Solution Framework Template (Please refer to page 11 from “Customizing CRM by Using the Microsoft Dynamics CRM Developer Toolkit.pdf” for more detail)

setup.cmd [InstallDir] [Project Namespace] [Project Long Name] {Organization Name}

Configuring CRM Explorer

1.    The CRM Explorer complements the CRM Solution Framework, providing the project factories required to open and build the solution from within Visual Studio. The Explorer manifests as a window within Visual Studio 2008 and provides direct access to CRM for creating and editing business units, security roles, and most importantly, entities. The CRM Explorer is linked to the solution framework which enables it to intelligently place generated code into the relevant solution framework project.

2. Open VS 2008 and Configure Your CRM Explorer (Please refer to page 13 from “Customizing CRM by Using the Microsoft Dynamics CRM Developer Toolkit.pdf” for more detail)

Note: Default Port Number for CRM is 5555.

Generating Entity Wrapper Class

1. The EntityWrappers project supports a project factory that enables integration with CRM by means of examining the CRM metadata and generating code within the project to support the entities that exist. The core purpose of this project is to expose the CRM entities and their corresponding attributes as classes and properties respectively to enable code to be developed to interact with the entities.

2. For each CRM entity that the developer selects, two files will be created namely: [entityname].cs and [entityname].Attributes.cs (where [entityname] represents the name of the Entity within CRM). These files split a single class named after the entity through partial classing. The [entityname].Attributes.cs file contains all of the attributes present on the entity at the time of creation.

Note: A major reason for separating the attributes into a separate file is because of their volatility throughout the development phase. The [entityname].attributes.cs file should not be manually edited by the developer as it supports re-generation via the CRM Explorer.

3. Open CRM Solution Framework Solution from your installed directory. Right-click on entity you want to generate wrapper class from CRM Explorer. Then, click “Generate Wrapper Class”.

I will tell you how to convert entity wrapper class to dynamic entity, and how to implement library programs that support CRM SDK operations in my next posts. If you have questions about this post, either leave a comment or email me at Thanks.

CRM Development Toolkit
Customizing CRM by Using the Microsoft Dynamics CRM Developer Toolkit
Developing Your CRM xRM Applications (Part - I)

Tuesday, December 22, 2009

XRM Notebook has been listed as a Technical Blog in Microsoft Dynamics Community

Today, my technical blog, XRM Notebook, has been listed as a XRM Technical Blog  in Microsoft Dynamics Community. Thanks to Nick Hoban who gives me a chance to participate and contribute my knowledge in our Dynamics CRM Community.

Community added another XRM blog to the CRM blogs
Microsoft Dynamics CRM Blogs

Thursday, December 10, 2009

Offline Client Error On Data Synchronization

Last week, my users complaint that they cannot see migrated data in some offline client laptops. I checked synchronization filter, CRM user data and both are working fine.

Finally, my colleague suggest me to do following steps:
  1. Go Online
  2. De-activate Local Data Group which has synchronization problem, and
  3. Go Offline
After synchronization process, You will not find no data at all. Then,
  1. Go Online
  2. Activate Local Data Group, and
  3. Go Offline again
You will get all data that were never synchronized before. It is something like restart process and I don't know how to explain this to user. The following are the list of screen shots for your reference:

1. Local Data Group (You can only see it after you go online)

2. De-activate Data Group

3. Activate Data Group

4. Filter Data Group

CrmException: transactionCurrencyId needs to be supplied to format a transaction money field.

Sometime you may find above error when you tried to open a record in MS CRM. This happened because there is no data in transactioncurrencyid attribute defined in your record. (For my case, it is related to data migration issue.) This transactioncurrencyid field is related to money data type attribute.

Resolution: Query the default  transactioncurrencyid (guid) in your organization and update from SQL. Please backup your database before you start this process.

Sometime, it can also happened if you take out existing money attribute from your CRM entity. In this case, adding one money attribute to that entity will solve your problem. Weird Thing!!!

Thursday, December 3, 2009

MSSQL Synonym Generator

Sometime, we may need to reference tables and views across two or more databases. For example, in CRM extension development, we used to keep our extended store procedures and views in external database. Those stored procedures and views will pull out data from ORGNAME_MSCRM database.

In this case we have to refer objects from MSCRM database with four-part identifiers
It will be very time consuming job and very difficult to maintain the code, if we are referencing those four-part identifiers in our stored procedures and views. Moreover, SQL Server will never check validity and existent of base objects at synonym create time. So, the best way is used the program to generate synonyms in external database.

Below is the screen shots of my SQL Synonyms Generator program. It will read stored procedures, views and functions from source database and automatically create synonym at another database. You can also filtered sys objects by user defined data types.

System Requirements:
  • VS .NET Framework 2.0
Download Link:
MSSQL Synonyms Generator (Application)
MSSQL Synonyms Generator (Source Code)