2
votes

I've built a plugin for Microsoft Dynamics CRM 2013 Online platform. The plugin is registered at Delete of my_custom_entity. It is synchronous and post-operational. Impersonation is set to Calling user. As far as I know the plugin should be fired with the calling user's privileges etc. with these settings.

I can't figure out why, but my the plugin is always run under "SYSTEM" user. I've tried to use two different system users with no luck whatsoever. It's kind of a problem because my plugin is calling a workflow and the workflow is sending an email. SYSTEM user can't send emails though.

Is this something new in CRM 2013? I tried to Google but couldn't find anything relevant. I already tried to unregister and register my plugin assembly again. No difference.

How can I change my plugin registration so that it would run on behalf of a user who fires the plugin (who deletes an entity).

Thank you

3
did you try to use an older plugin registration tool? I'm worried that can be a bug of the plugin registration you are using. If I have time I will set up a similar case with my online trialGuido Preite
@GuidoPreite Actually I just noticed some weird behavior in a plugin registration tool. It won't let me change the impersonation only but one time. When I restart the program then it lets me to do it again, but only once. I'll definitely try to get another version an give it a try. I'll let you knowkivikall
Plugin registration tool I'm using now and facing a problem is version 6.1.1.1143 64bit. I have Windows 8 machine (plugin registration tool tells me Windows Version: Microsoft Windows NT 6.2.9200.0 64bit)kivikall
I've had problems with the plugin registration tool switching my changes with run as user as well. I switched back to version 6.1.0.519 and things started working again. If you have a dropbox account send me a mail and I'll share it with you.Arthur
I just downloaded 6.1.0.519 and it helped a bit. I'm now able to set Run as user to something else than "Calling user". If I do so everything works well. But still if I set "Run as" to Calling user my plugin fires as it would be SYSTEM user who triggered it. I don't recall having this problem earlier. Clearly there was a problem with the latest plugin registration tool though.kivikall

3 Answers

4
votes

How are you obtaining your service reference?

If you do it like this you should get all the actions performed as the user who triggered the plugin.

// Obtain the organization service reference.
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

If you are passing a null value you will get the system user, e.g. serviceFactory.CreateOrganizationService()

IOrganizationServiceFactory.CreateOrganizationService

Specifies the system user that calls to the service are made for. A null value indicates the SYSTEM user. When called in a plug-in, a Guid.Empty value indicates the same user as IPluginExecutionContext. UserId. When called in a custom workflow activity, a Guid.Empty value indicates the same user as IWorkflowExecutionContext.UserId. Any other value indicates a specific system user.

0
votes

YOu should use context.InitiatingUserId rather.

IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId);
0
votes

The InitiatingUserId will be the user who triggers the delete action. In Delete context, UserId will be System where the platform is using.