Trying to get user's manager: Getting SPServiceContext with SiteSubscriptionId of {00000000-0000-0000-0000-000000000000}
-
10-12-2019 - |
Question
I am trying to get a user's manager with this code:
SPSecurity.RunWithElevatedPriviliges(delegate
{
SPSite site = new SPSite(SPContext.Current.Site.Url);
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);
//Note that I have an SPUser object, user, previously defined.
UserProfile userProfile = profileManager.GetUserProfile(user.ID);
UserProfile managerProfile = userProfile.GetManager();
});
My problem is that I am getting a null UserProfileManager. I suspect it's because the SPServiceContext has a SiteSubcriptionId of {00000000-0000-0000-0000-000000000000}.
I am debugging this on my local SharePoint server. I am running it on a development environment on Windows 7. Does this error indicate a problem with my environment?
Is there a better way to get the manager of a given SPUser?
EDIT:
It appears neither my local machine or my test server has the User Profile Service set up properly. So that is probably why it's not working. I'm going to attempt to get that working and see if I still have the problem.
Solution
The empty Guid here actually is not concerning. The SiteSubscriptionId will always be a blank Guid unless you have multi-tenancy enabled in your environment.
Enabling Multi Tenant Support in SharePoint 2010
You may need to add permission for your user on the User Profile Service Application.
In Configure User Profile sync connections they were trying to get the UserProfileManager
via PowerShell and getting an error (NullReferenceException
) but resolved it by ensuring the user account attempting to get the UserProfileManager
had permissions:
1) As a administrator with full control
2) connection permissions as full control
Then you have access to the connection manager and can programatically access the connections.
OTHER TIPS
In addition to the Administrator and Permission on the UPSA, I needed to add the SharePoint setup user as db_owner on the ProfileDB.