Part One - Preparation
This post deals with how to deploy more than one steps of a using developer toolkit. Meaning how to design a plug in that will get triggered by more than one event. I will try to put as much sample codes and screen shot possible. Before going into it let us go through the terminology used throughout the post.
Event – Trigger Request, for example Create, Assign, Set State etc. I will be using create and update
Handler – Code snippet that handles an event.
Package Project – CRM 2011 package project that contains reference of all the other crm 2011 projects added to the solution.
At first open visual studio and open the solution you want to use. In this case I have used a blank solution. When the solution is loaded/created right click the solution in the solution explorer and then select add new project. On the search box type CRM the following list appears. Select “Dynamics CRM 2011 Package”, then name your project and then click OK.
For my understanding I always consider the package project as a register where the deployment information for the workflows and plugins are stored. I am sure there is a genius definition of CRM Package. But hey this blog is not for geniuses.
Secondly, right click the solution and click add project again and in the search box type crm. But this time click “Dynamics CRM 2011 plug-in Library”. This will be the project where all the plug-in handlers for the solution will reside. Up to now we have not written a single line of code. And our solution explorer looks something like following
Now click on the CRM Explorer and then select the entity on which you want to create the handler. In our case we are using Invoice entity. Once the entity is selected, right click it and select Create Plug-in. A window that looks very similar to the screen for registering plug-in step appears. You need to select the Message as well as the correct pipeline stage. Notice that the name of the class on top right of the screen changes as you select the correct pipeline stage and message.
Since we are going to use the same the class on multiple events I have given a generic name to the class. When we click “Ok” button we will see in our plug-in project, a new class named “InvoiceHandler” got created. Also if we click on “RegisterFile.crmregister” in the package project we will see XML similar to the one given below. Notice that all the id fields are now empty guid. They will be replaced with the actual guid once the solution is deployed.
<?xml version="1.0"?> <Register xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/crm/2011/tools/pluginregistration"> <Solutions> <Solution Assembly="TestSolution.Plugins1.dll" Id="00000000-0000-0000-0000-000000000000" IsolationMode="Sandbox" SourceType="Database"> <PluginTypes> <Plugin Description="Plug-in to InvoiceHandler" FriendlyName="InvoiceHandler" Name="TestSolution.Plugins1.InvoiceHandler" Id="00000000-0000-0000-0000-000000000000" TypeName="TestSolution.Plugins1.InvoiceHandler"> <Steps> <clear /> <Step CustomConfiguration="" Name="InvoiceHandler" Description="Post-Operation of Invoice Create" Id="00000000-0000-0000-0000-000000000000" MessageName="Create" Mode="Synchronous" PrimaryEntityName="invoice" Rank="1" SecureConfiguration="" Stage="PostOutsideTransaction" SupportedDeployment="ServerOnly"> <Images /> </Step> </Steps> </Plugin> </PluginTypes> </Solution> </Solutions> <XamlWorkflows /> </Register>
This concludes our preparation part for the problem. On the next part I will discuss how to use this architecture to register more than one steps (and plug in if necessary) and deploy the solution in one go.
No comments:
Post a Comment