Monday, January 28, 2008

MSCRM 4.0 Plug-in: Quick Start Guide Part 2 (Debugging)

How to debug plug-in with Visual Studio 2005:

1. Compile the assembly, copy following files to the MSCRM server assembly folder
(e.g. C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly):

     *.dll
     *.pdb

2. When registering the plug-in, make sure Disk is selected as the Location for the assembly.


3. Back to Visual Studio. Under Debug menu, select Attach Process… And attach to the relevant process which will trigger the debugger:


4. Back to Visual Studio and set break points:


5. Back to MSCRM, and perform an action which will trigger the debugger (based on the message registered for the entity)

6. The Local window will be able to show some information for debugging:


Sunday, January 27, 2008

MSCRM 4.0 Plug-in: Quick Start Guide Part 1 (Creation)

How to create plug-in for MSCRM 4.0:

1. Create a Class Library project.


2. Assign a key to the plug-in. Plug-in assembly must be strong-named and signed with a key. If no existing key available, a new key can be generated:


3. Add following MSCRM 4.0 SDK references:

       microsoft.crm.sdk.dll
       microsoft.crm.sdktypeproxy.dll

       using Microsoft.Crm.Sdk;
       using Microsoft.Crm.SdkTypeProxy;

4. Plug-in must implement the IPlugin interface, for example:

       public class CaseNumber: IPlugin
       {

       }

5. Sample code for generating Case Number (ticketnumber):

public class CaseNumber: IPlugin
{
    public void Execute(IPluginExecutionContext context)
    {
        // Ensure DynamicEntity is available
        if (context.InputParameters.Properties.Contains("Target") &&
            context.InputParameters.Properties["Target"]is DynamicEntity)
        {
            // Retrieve the DynamicEntity
            DynamicEntity entity =
                (DynamicEntity)context.InputParameters.Properties["Target"];
// Ensure the DynamicEntity is incident if (entity.Name == EntityName.incident.ToString()) { // Update the ticketnumber Property entity.Properties["title"]= DateTime.Now.ToString(); } } } }
6. Compile and register the plug-in with the MSCRM Plug-in Registration Tool:


7. The plug-in can be stored (deployed) to MSCRM database, the server hard disk or the GAC. If the Disk option is selected, the assembly file must be placed into C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly at the server (assuming this is the MSCRM installation path).


8. Register new step for the plug-in:


9. For example, the assembly subscribed to Create event (Message), incident as the Primary Entity, and the Stage is Pre Stage:


10. If Pre-Image or Post-Image is required by the plug-in, a new Image can be registered:


11. Once the plug-in registered, it can be tested by performing relevant actions to trigger the plug-in event.