Tuesday 2 July 2013

CRM 2011: Deploying More Than One Steps using Developer toolkit

Part Two - The Final Steps

On my previous post I have discussed the steps for the preparation needed for creation of creating a plugin which can be used to handle multiple messages. This part will describe the final few steps needed to create the plug in.

For this you need to go to the RegisterFile.crmregister. Locate the tag “Step”. Copy the content of the tag and paste it right underneath the closing of the tag. Notice that it contains MessageName, Mode, PrimaryEntity, Stage and some other attributes. On the new step change attribute MessageName to “Update”. This is how you are telling the package project that you have added another step to the same plugin. The RegisterFile should look like following.


<?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>
            <Step CustomConfiguration="" Name="InvoiceHandler" Description="Post-Operation of Invoice Create" Id="00000000-0000-0000-0000-000000000000" MessageName="Update" Mode="Synchronous" PrimaryEntityName="invoice" Rank="1" SecureConfiguration="" Stage="PostOutsideTransaction" SupportedDeployment="ServerOnly">
              <Images />
            </Step>
          </Steps>
        </Plugin>
      </PluginTypes>
    </Solution>
  </Solutions>
  <XamlWorkflows />
</Register>




Open invoice handler and local the following line.


base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Create", "invoice", new Action<LocalPluginContext>(ExecuteInvoiceHandler)));



Again copy and paste the line just underneath the original line. After that change second parameter to “Update”. Now the lines look like this.


base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Create", "invoice", new Action<LocalPluginContext>(ExecuteInvoiceHandler)));

base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "invoice", new Action<LocalPluginContext>(ExecuteInvoiceHandler)));


That’s it. Just right click the package project and click deploy and the code will be deployed to the server. Finally after deployment the xml file should look like this,

<?xml version="1.0" encoding="utf-8"?>
<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="6f5c9e09-58e3-e211-8a00-3c4a92dbdc39" IsolationMode="Sandbox" SourceType="Database">
      <PluginTypes>
        <Plugin Description="Plug-in to InvoiceHandler" FriendlyName="InvoiceHandler" Name="TestSolution.Plugins1.InvoiceHandler" Id="715c9e09-58e3-e211-8a00-3c4a92dbdc39" TypeName="TestSolution.Plugins1.InvoiceHandler">
          <Steps>
            <clear />
            <Step CustomConfiguration="" Name="InvoiceHandler" Description="Post-Operation of Invoice Create" Id="725c9e09-58e3-e211-8a00-3c4a92dbdc39" MessageName="Create" Mode="Synchronous" PrimaryEntityName="invoice" Rank="1" SecureConfiguration="" Stage="PostOutsideTransaction" SupportedDeployment="ServerOnly">
              <Images />
            </Step>
            <Step CustomConfiguration="" Name="InvoiceHandler" Description="Post-Operation of Invoice Create" Id="745c9e09-58e3-e211-8a00-3c4a92dbdc39" MessageName="Update" Mode="Synchronous" PrimaryEntityName="invoice" Rank="1" SecureConfiguration="" Stage="PostOutsideTransaction" SupportedDeployment="ServerOnly">
              <Images />
            </Step>
          </Steps>
        </Plugin>
      </PluginTypes>
    </Solution>
  </Solutions>
  <XamlWorkflows />
</Register>