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.”
I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.
IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.
THANK YOU, AND LET'S KEEP LEARNING TOGETHER.
CARL