Friday, February 20, 2015

How to Import a Solution With a Custom Action and a Plugin Step Registered Against the Custom Action in CRM 2013 SP 1 UR 1

This is a very specific bug that was fixed with CRM 2013 SP1 UR 2.  But if you aren't there yet, here is the issue and the steps to fix it:

Issue:

Attempting to import a Solution with a Plugin Step(s) registered against Custom Action results in the following import error: "sdkmessage with Id = {Guid} Does Not Exist"

Cause:

When CRM 2013 SP1 UR 1 (could be earlier versions as well) imports a Custom Action it is imported as a workflow and the XML in the customizations.xml file looks something like this:

  <Workflows>
    <Workflow WorkflowId="{cf3d243d-e065-4da1-b882-adfecdb6fe9d}" Name="DDLCustomAction">
      <XamlFileName>/Workflows/DDLCustomAction-CF3D243D-E065-4DA1-B882-ADFECDB6FE9D.xaml</XamlFileName>
      <Type>1</Type>
      <Subprocess>0</Subprocess>
      <Category>3</Category>
      <Mode>0</Mode>
      <Scope>4</Scope>
      <OnDemand>1</OnDemand>
      <TriggerOnCreate>0</TriggerOnCreate>
      <TriggerOnDelete>0</TriggerOnDelete>
      <AsyncAutodelete>0</AsyncAutodelete>
      <SyncWorkflowLogOnFailure>1</SyncWorkflowLogOnFailure>
      <StateCode>1</StateCode>
      <StatusCode>2</StatusCode>
      <CreateStage>40</CreateStage>
      <RunAs>1</RunAs>
      <SdkMessageId>{63d9c5b6-74b8-e411-80ef-000d3a100fad}</SdkMessageId>
      <UniqueName>DDLCustomAction</UniqueName>
      <IsTransacted>1</IsTransacted>
      <IntroducedVersion>1.0</IntroducedVersion>
      <IsCustomizable>1</IsCustomizable>
      <PrimaryEntity>none</PrimaryEntity>
    </Workflow>
  </Workflows>


Notice the SdkMessageId and UniqueName.  When this gets imported, CRM only uses the UniqueName, it doesn't use the SDK Message Id, it actually creates a new SDK Message Id.  This is the bug.  If you're just importing a Custom Action, no issues, but when you attempt to import a Plugin Step registered against the Custom Action, the Id's won't match up:

  <SdkMessageProcessingSteps>
    <SdkMessageProcessingStep Name="Xrm.Plugins.Merge: new_DDLCustomAction of  any Entity" SdkMessageProcessingStepId="{0f4fdb54-72b8-e411-9c1a-005056827e6d}">
      <PluginTypeName>Xrm.Plugins.Merge, Xrm.Plugins, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0c1faab69f9562d5</PluginTypeName>
      <AsyncAutoDelete>0</AsyncAutoDelete>
      <InvocationSource>0</InvocationSource>
      <Mode>0</Mode>
      <Rank>1</Rank>
      <SdkMessageId>{63d9c5b6-74b8-e411-80ef-000d3a100fad}</SdkMessageId>
      <EventHandlerTypeCode>4602</EventHandlerTypeCode>
      <Stage>40</Stage>
      <IsCustomizable>1</IsCustomizable>
      <IsHidden>0</IsHidden>
      <SupportedDeployment>0</SupportedDeployment>
      <IntroducedVersion>1.0</IntroducedVersion>
      <SdkMessageProcessingStepImages />
    </SdkMessageProcessingStep>
  </SdkMessageProcessingSteps>


Notice there is no UniqueName, just the SDK Message ID.  This is why the "sdkmessage with Id = {Guid} Does Not Exist" error is getting created. 

Workaround:

There is a workaround if you're unable to upgrade to UR2, update the GUIDs in the solution to match the newly created Id.
  1. Import just the Custom Action Process if it doesn't already exists. This will create the SDK Message Id.
    image


  2. Get the newly created Id.  (There are multiple ways, this is the easiest universal way I could think of) do an advanced Find on Sdk Messages, where the Category Name is "CustomOperation".
    image


  3. Locate the Custom Action that you want, and use the debugger tools (F12) to get the actual html itself for the action.  In it you can find the GUID: 
    <a tabindex="0" title="new_DDLCustomAction" class="ms-crm-List-Link" id="gridBodyTable_primaryField_{8DEDACA9-F32C-4F90-BF6E-A87464C70F72}_1" href="#" target="_self">new_DDLCustomAction</a>

  4. Do a search and replace in the customizations.xml for the current SdkMessageId listed (in my example it would be "63d9c5b6-74b8-e411-80ef-000d3a100fad") and replace all with the newly created Guid ("8DEDACA9-F32C-4F90-BF6E-A87464C70F72").


  5. Rezip your solution.

That's it, your import will work just fine.  The biggest headache is you'll need to do this for each and every org that you import it in, making it a nasty fix if you have multiple environments / org.