Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

Get the name of the initiating user by its ID using a plugin

$
0
0

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:

Plugin to retrieve username

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<SystemUser>().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!


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images