Hi,
This is a similar question to the following thread: http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/016b7e05-7d84-416f-8e71-159c9782d36f
In CRM 2011 online I have an asynchronous plug-in which runs on create, update and delete. The 3 plug-in steps (create, update delete) are all registered to run in the calling user's context. In my code I get the organization service thus (for create, update and delete):
// Get the IPlugin Context _context = (IPluginExecutionContext) serviceProvider.GetService(typeof (IPluginExecutionContext)); // Get the organization service IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory) serviceProvider.GetService(typeof (IOrganizationServiceFactory)); _organizationService = serviceFactory.CreateOrganizationService(_context.UserId);
When the plug-in runs for both Create and Update it does indeed run as the calling user, however when it's triggered because of a Delete it runs under the system user "SYSTEM".
I understand that I can use the _context.InitiatingUser if I truly want to run as the person who triggered the plug-in, but what I don't understand is why the Delete is running as system user when I haven't told it anywhere to do that (presumably for deletes _context.UserId is the Guid of the system user).
Under what circumstances does this happen, is it because it's asynchronous, is it because it's a delete or is it some quirk of CRM on-line?
As it happens this is exactly what I want to happen, but I'm slightly nervous leaving it in case it's a bug/quirk that MSFT "fix" later on. I could set the "Run in User's Context" on the registration step to "System", but I'm a bit confused because in the plug-in registration tool it says "SYSTEM (disabled)" so I'm not sure if it's valid to do that?
Thanks,
LJ