Home › Dynamics 365 Customer Engagement (CRM) › Dynamics 365 – Impersonate a User in Plugin
Dynamics 365 Customer Engagement (CRM) · Jul 29, 2018

Dynamics 365 – Impersonate a User in Plugin

In Dynamics 365, when testing plugins, you can change which user the plugin runs under. Do to this, open the step in the Plugin Registration Tool. We have a plugin that runs on create of an account, that creates a new Task. We will select this to run under the context of a user, Alan Steiner by setting Run in User’s Context:

Our user Alan Steiner does not have privileges to create a new task in the system:

So what happens when we try to create a new task (as either Alan or any other user)? Create a new account:

Our plugin code will run. Now go to System Jobs. You will see the plugin failed to execute:

Open the job, and you will see the details show the user does not have access to the prvCreateActivity privilege:

Set the plugin back to the Calling User to run as normal:

Note you can also impersonate a user within your plugin code by using

serviceFactory.CreateOrganizationService(UserGuid);

From the documentation: “When called in a plug-in, a null value indicates the SYSTEM user and a Guid.Empty value indicates the same user as IPluginExecutionContext. UserId. Any other value indicates a specific system user.”

Leave a Reply

Your email address will not be published. Required fields are marked *

Carl de Souza
KEEP LEARNING. KEEP BUILDING.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.