Dynamics CRM 2011 Plugins: Development, Debugging and Deployment

Leave a comment

By Hector Villafuerte

Hector Certifications

This article shows you how code, debug and deploy a plugin in MS Dynamics CRM 2011 On-Premise. Let’s assume that your company needs to identify the leads not only by the Guid, but by using a sequential numeric number. I tried to screen shot all steps in my computer to have a easy to follow tutorial.

First we’ll add a new field called AutoNumber to the Lead entity, which value will be calculated using a plugin.

Open your MS CRM 2011 in your browser and go to settings:

Click the customization menu in the left side bar.

Click “Customize the System”.

Expand Entities.

Scroll down, select and expand the “Lead” and select “Fields” option. Then click the New button to create a new custom field for the Lead entity.

Enter the following information as shown below:

Click “Save and Close”, select forms under Lead and select Information form and click the link.

Notice that the Field Explorer is shown in the right side.

Click the Filter drop-down arrow, select Custom Fields and select “Auto Number”. Drag Auto Number field to the Lead Form.

Click Auto Number and The Field Properties – Webpage Dialog window opens. Click Fields is read-only and click OK.

Save and Close and Click Publish All Customizations.

 

Once you finish adding the custom field: AutoNumber  to the Lead entity, you can start coding the PlugIn.

Download Microsoft Dynamics CRM 2011 Software Development Kit (SDK)

http://www.microsoft.com/en-us/download/details.aspx?id=24004#

The SDK will unpack the sdk directory in the desire directory.

Start Visual Studio 2012. Create a new Project type “Class Library” and named it “Auto Number”:

Select Add Reference in the “Solution Explorer”.

Browse the sdk directory an select the following assemblies:

Microsoft.Crm.SdkTypeProxy.dll: Defines requests and responses for messages business data model specific (non-core) messages as well as enumerations required for working with organization data.

Microsoft.Xrm.Sdk.dll: Defines the core xRM methods and types, including proxy classes to make the connection to Microsoft Dynamics CRM simpler, authentication methods, and the service contracts.

 

Rename the default class file to AutoNumber.cs and write the following code:

 

Write the code as shown below:

Build the solution.

An error prevent to do the build because we are missing the serialization assembly. Add System.Runtime.Serialization:

After a successful compilation, It is time to sign the assembly. Go to Project properties. Select Signing in the left side:

Check Sign the assembly and select New to Create the Strong Name.

Click OK and select the strong name key created.

Now the plug-in is ready to be deployed. In order to do so, run the Plug-in registration Tool located in the SDKbinpluginregistration.exe.

In the Plugin Registration Tool, create a new connection.

Enter the connection information as shown below:

Once the connection is created you’ll see an item under server crm connection.

Click connect:

Click Register and Register New Assembly:

Browser the created assembly. Select the assembly AutoNumber.

Select the database location where the assembly will be store. Click Register Selected Plugins.

Once the assembly is registered, Expand the Registered (Assembly) AutoNumber. Select the inner item: (Plugin) AutoNumber – Isoletable.

Right click and select “Register New Step” in the popup menu.

You’ll get the next screen:

Enter the information as shown below.

Click Register New Step.

That’s it. Now you can create a new lead and test your plugin.

How to Debug the Plugin?

In case you need to debug your plugin, you should copy the assembly file and the pdb file in the CRM installation directory:

C:Program FilesMicrosoft Dynamics CRMServerbinassembly

Register the new assembly using the Disk option instead of the Database option for the assembly storage.

Fill out the fields as shown below:

Click “Register New Step”.

Attach the wp3 process to visual studio in case your server is the local computer.

 

 

Set a breakpoint.

Open your browser and create a Lead.

The execution will stop in the indicated breakpoint in Visual Studio.

 

The following screen show an entire view of the code.

I hope this tutorial is simple enough to help you to get started with MS CRM Plugins. There are many variations and details depending of you Dynamics CRM server configuration. This tutorial focuses in a local On-Premise installation. In case of Remote and Hosted installation, things will be different. Also Dynamics CRM Online  2011 has some limitations in debugging and coding. I will expand this in another article.

 

Leave a Reply