1

I'm having trouble with getting user's manager data in SharePoint Javascript Model.

I'm using context.get_web().get_siteUserInfoList(); through SiteUserInfoList. What I got back is a bunch of info about a user (Title, JobTitle, Department, Office etc...) except who's that user manager.

What I'm missing? Or how can i get user's manager?

1

This blogpost describes how to get the current users manager by using the SPservices library.

The SPServices libary can be found on codeplex.

  • Note, this would require having SharePoint Server with a User Profile Service Application. – Mike Oryszak May 10 '13 at 13:18
  • Thanks, I gave it a shot but ultimately got it working through SP.UserProfiles.UserProfilePropertiesForUser – sebz May 13 '13 at 13:12
3

Hi i know this is an old question, but here's a result that doesn't use SPServices:

Note that this answer is inspired from this post

The method to get the manager of a user by user_email:

function getManagerOfUser(user_email, onComplete) {
    SP.SOD.executeOrDelayUntilScriptLoaded(function () {
    // Create the client context and get the PeopleManager instance.
    var clientContext = SP.ClientContext.get_current();
    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);

    // Get user profile properties for the target user.
    // Specify the properties to retrieve and create the UserProfilePropertiesForUser object.
    // Then get the requested properties by using the getUserProfilePropertiesFor method.
    var profilePropertyNames = ["Manager"];

    var userProfilePropertiesForUser = new SP.UserProfiles.UserProfilePropertiesForUser(clientContext,
        "i:0#.f|membership|" + user_email,
        profilePropertyNames);

    var userProfileProps = peopleManager.getUserProfilePropertiesFor(userProfilePropertiesForUser);

    clientContext.load(userProfilePropertiesForUser);
    clientContext.executeQueryAsync(function () {
        if (userProfileProps[0]) {
            var user = clientContext.get_web().ensureUser(userProfileProps[0]);
            clientContext.load(user);
            clientContext.executeQueryAsync(function () {
                onComplete(user);
            }, function (sender, args) {
                console.log(args);
            });
        } else {
            onComplete(null);
        }
    }, function (sender, args) {
        console.log(args);
    });
   }, 'SP.UserProfiles.js');
}

To use the code:

getManagerOfUser("me@mydomain.com", function (result) {
  console.log(result.get_title());
});

Note that the result is of type SP.User

0

You can use REST API to get it easily:

_spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties"

For more information, read Get Current Logged in User & Manager using REST API in SharePoint

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.