Thursday, February 18, 2016

Impersonate the Plugins MSCRM C#

Hi,

Today i have a scinario to impersonate the plugin for that we followed below steps.

Open Plugin Registration tool and open the plugin which you need to impersonate. Pass the GUID in Unsecure Configuration


Once Done. Update the step and 

public Impersonate(string unsecure)
            : base(typeof(Impersonate))
        {
            base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "ENTITYNAME",
                new Action<LocalPluginContext>(ExecuteImpersonate)));
            if (!Guid.TryParse(unsecure, out ssisUserGuid))
            {
                throw new InvalidPluginExecutionException(CustomMessagesResources.Error_PostCustomerAssign_ConfigRead);
            }

        }
 protected void ExecutePostCrmDealUpdateSecurity(LocalPluginContext localContext)

        {
 EntityReference callingUser = new EntityReference
                        {
                            LogicalName = "systemuser",
                            Id = ssisUserGuid
                        };
                        OrganizationServiceProxy serviceProxy = (OrganizationServiceProxy)service;

                        serviceProxy.CallerId = callingUser.Id;
}

The above code will impersonate the plugin to the user which you have mentioned in the plugin unsecure configuration.

No comments:

Post a Comment

How to hide Navigation and Command Bar's in Model Driven App ?

  Introduction: In this Blog we will see how to hide Navigation and Command Bar in Model Driven App. Implementation Steps: Navigate to  http...