Microsoft Dynamics CRM 4.0 Plug-Ins

Microsoft Dynamics CRM 4.0 Plug-Ins


With the help of Plug-Ins you can handle events which are raised by CRM Server and then you can execute your custom code. Essentially a Plug-In is a .net assembly containing your code which you want to execute in response to CRM events raised by the CRM Server. Hence you can do a lot of customization to CRM using Plug-Ins, for e.g. whenever a lead is created or updated you can handle events to save the lead in some other database or you can do any auditing task. Since the code is executed on the server, you can be sure that it will get executed even when an entity is created using Import or Web Service API.

Execution Pipeline

When developing Plug-Ins it is important to understand the event execution pipeline. Messages in CRM are operations like create, update, delete etc which are called on an entity. Whenever a message is requested the execution pipeline runs like this

Pre-Event->Core Operation (Implemented by CRM)->Post- Event.

We can write Plug-ins to execute our code either in Pre-Event or Post-Event.

Developing Plug-Ins

These are the steps to develop a Plug-In

1. Create a new Class Library project in visual studio.

2. Add Microsoft.Crm.Sdk.dll and Microsoft.Crm.SdkTypeProxy.dll as references to this project (These assemblies will be in CRM SDK’s bin folder).

3. Add a new class implementing the IPlugin Interface.

4. Add your code to the Exceute method of the IPlugin Interface.

using Microsoft.Crm.Sdk;
namespace PlugInNameSpace
public class ExamplePlugIn : IPlugin
public void Execute(IPluginExecutionContext context)
//Add your code here

5. Sign the assembly with a strong-key

6. Build the project to generate the dll.


This Interface which is a parameter to the Execute method contains contextual information. It has methods to create a CrmService or MetaDataService. Also through this interface we can figure out the bussinessunitid, organizationid, messagename etc.

Plug-In Deployment

For deploying the plug-in we built, we require a registration tool. This registration tool ,PluginRegistration is available with the CRM SDK. With this tool we can register our plug-in and configure other properties of the plug-in like which messages and which entities cause the plug-in to execute. This tool is distributed with the SDK as source code and we need to compile it to make an .exe out of it. The source code can be found at CrmSdk4\SDK\Tools\PluginRegistration and compilation guidelines can be found in the same folder in the file readme.doc.

Steps for registering the Plug-In

1.Start the PluginRegistration.exe application

2. Specify the CRM Server, Port, Domain, UserName and Password and click connect.

3. Select the organization for which you want the plug-in to be deployed.

4. Select Register New Assembly, select the location of your dll and select Database as the deployment location.

5. Now Click Register Selected Plug-ins.

6. The plug-in is registered now, next we have to register the steps .( With Steps we can specify information such as the entity and message that will cause a plug-in to execute, as well as the stage it will execute in).

7. Select the Plug-In registered and select Register New Step option.

8. Specify MessageName, Primary Entity and other options and then Click Register New Step



No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: