Get CCA agent systemuserid

Mar 30, 2012 at 9:15 AM
Edited Mar 30, 2012 at 2:18 PM

You can disregard this question. I figured out although I was unable to get this in the Agent Desktop UI, I could get it within a control so I added the dialog I wanted in the control and displaying it from there.

Mar 30, 2012 at 2:43 PM

You can get it from the agent desktop in two ways..
The easiest is to get it from desktopservices :


The slightly more difficulte way, though it works wherever you are and will get you a bit more info is to get it from the authentication service.

AuthenticationService CrmAuthService = (AuthenticationService)AifServiceContainer.Instance.GetService<AuthenticationService>();
Guid userId = CrmAuthService.WhoAmI.UserId;
Guid orgId = CrmAuthService.WhoAmI.OrganizationId;
Guid bizUnitId = CrmAuthService.WhoAmI.BusinessUnitId;

Hope that helps,


Mar 30, 2012 at 2:47 PM
Edited Mar 30, 2012 at 3:03 PM

Hi Matt,

Thanks for the reply. Using DesktopService.AgentId I'd always get Guid.Empty. Maybe it was because I was using it on the constructor of the main window. I'll try it again when it finishes loading controls I guess and see if it works. What I wanted was to show the user a popup dialog for him to select a status before initiating any CCA hosted apps. If the agent does not select a status he/she shouldn't be allowed to log on to CCA and the application should close. So I wanted to do this before loading the CCA apps to speed up things. In the end I put the dialog in a hosted control and invoking it from there after hosted apps & controls are loaded.

I used your second way and put the dialog back in the agent desktop now. It works great.

                AuthenticationService CrmAuthService = (AuthenticationService)AifServiceContainer.Instance.GetService<AuthenticationService>();
                WhoAmIRequest whoAmIReq = new WhoAmIRequest();
                WhoAmIResponse whoAmIRes = (WhoAmIResponse)CrmAuthService.CrmService.Execute(whoAmIReq);
                Guid userId = whoAmIRes.UserId;