Search code examples
dynamics-crmmicrosoft-dynamics

In a Plugin registered to the "Merge" Message - how do I know what will be provided in the Target etc?


Supposed I register a Plugin Step to "Merge" of "account". Pic below.

How do I know what the Plugin context/target will provide me? Is there any documentation about what the Plugin context will provide for the different Messages you can register to?

enter image description here


Solution

  • A plugin message always has a corresponding OrganizationRequest and OrganizationResponse.

    In this case lookup the MergeRequest class. It has 4 custom properties:

    1. Target - an EntityReference pointing to the record that is supposed to be the remaining one.
    2. SubordinateId - a Guid referencing the record that is merged into the target.
    3. UpdateContent - an Entity containing the choices the user made regarding the merged fields.
    4. PerformParentingChecks - a bool allowing you to pre-emptively agree to any parenting changes during the merge.

    When you prefer to code early bound, you can use the IPluginExecutionContext to get the original MergeRequest like this:

    public void Execute(IServiceProvider serviceProvider)
    {
        var executionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
        var request = new MergeRequest { Parameters = executionContext.InputParameters };
        // Implementation continues here
    }