Hello,
I have the following problem:
I need the name of the initiating user in a plugin. I get the execution context supplied with the plugin. I can easily find out the ID of the initiating user:
context.InitiatingUserId
During my research I came across this question and its answer on how to get the name by the ID:
So I came up with this code trying to get the full name of the initiating user inside my OnExecute(context)-Function:
protected override void OnExecute(PluginContext context) { var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); var service = serviceFactory.CreateOrganizationService(context.InitiatingUserId); var systemUser = service.Retrieve("systemuser", context.InitiatingUserId, new Microsoft.Xrm.Sdk.Query.ColumnSet(true)); var initiatingUser = systemUser.ToEntity().FullName; }
Unfortunately, I keep getting the Error "The name 'serviceProvider' does not exist in the current context".
What could be the cause of this error? Is there another way to find out the name of the initiating user?
I am grateful for any help!