Thursday, August 2, 2012

Get Entity details in Merge Plugin in MS CRM 2011



public void Execute(IServiceProvider serviceProvider)
{
    // Obtain the execution context from the service provider.
    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

    Guid winnerEntityid = Guid.Empty;
    Guid looserEntityId = Guid.Empty;

    // The InputParameters collection contains all the data passed in the message request.
    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference)
    {
             
                EntityReference winnerEntityLookup = (EntityReference)context.InputParameters["Target"];
                winnerEntityid = winnerEntityLookup.Id;

                if (context.InputParameters.Contains("SubordinateId"))
                    looserEntityId = new Guid(context.InputParameters["SubordinateId"].ToString());
                       
                // write you logic here
     }
}

1 comment:

Unknown said...

They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety. See the link below for more info.


#obtain
www.ufgop.org