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
     }
}

2 comments:

lee woo 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

sarah lee said...

I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. I would like to thank you for the effort you have made in writing this article.


edupdf.org