1

After going through the below link, I would like to achieve/get the same functionality in my SPO site using JSOM. How can I get list of all users reporting to perticular user using UserProfileManager?

How to get the reportees of a manager from a SPO site, any CSOM/JSOM APIs available for this module?

is there ant API in JSOM[only javascript] that is similar to the below userprofilemanager and GetDirectReports() :

   UserProfileManager userProfileManager = new 
        UserProfileManager(serverContext);  
   // Check whether the user profile and the manager user profile exist, 
      //and that they are not                  
        // the same user.            
        if (userProfileManager.UserExists(loginName))
        {
            // Retrieve the user profile.                
            UserProfile userProfile = 
          userProfileManager.GetUserProfile(loginName);  
    // Get the user's multiple levels of managers, peers, and 
    //direct reports.                 
            managers = new List<UserProfile>(userProfile.GetManagers());                
            peers = new List<UserProfile>(userProfile.GetPeers());                
            directReports = new List<UserProfile>
         (userProfile.GetDirectReports());
         }

Note:Want to make it a community post

2

Assuming that i:0#.f|membership|user.name@tenantname.onmicrosoft.com is the account of a manager. You can use the below REST API to get information about a direct reportees, managers and peers.

var accountName = "i:0#.f|membership|user.name@tenantname.onmicrosoft.com";
jQuery.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'",
    method: "GET",
    headers: { "Accept": "application/json; odata=verbose" },
    success: function (data) {  

        var managers = data.d.ExtendedManagers.results;
        var extendedReports = data.d.ExtendedReports.results;
        var directReports = data.d.DirectReports.results;
        var peers = data.d.Peers.results;
        console.log(data.d);

    },
    error: function (data) {
        console.log(JSON.stringify(data));
    }
});

Microsoft is now actively promoting REST API over JSOM. So, would suggest that you use REST API.

I tried something similar in JSOM, but it was not providing me details related to Peers, DirectReports.

The code I used is as below:

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
    SP.SOD.executeFunc('userprofile', 'SP.UserProfiles.PeopleManager', function () {
        getUserData();
    });
});

function getUserData(){

    var targetUser = "i:0#.f|membership|user.name@tenantname.onmicrosoft.com";
    var clientContext = new SP.ClientContext.get_current();
    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
    personProperties = peopleManager.getPropertiesFor(targetUser);
    clientContext.load(personProperties);
    clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);
}

function onRequestSuccess() {
    console.log(personProperties.get_userProfileProperties());

    var manager = personProperties.get_userProfileProperties()["Manager"];

    console.log(manager);

}

function onRequestFail(sender, args) {
    console.log("Error: " + args.get_message());
}   
0

It can be achieved by using SharePoint 2013 Search REST API. Follow below steps:

  1. Create a Managed Property named Manager (for example) in Search Schema under Queries and Results in Search Service Application, choose People:Manager when Adding a Mapping and enable some necessary features(please per the AccountName property).
  2. Click Crawled Properties in Search Schema, enable Include in full-text index in the Manager property created in step1.
  3. Enable Alias and Indexed in Search Settings in User Profile Service Application.
  4. Start a full crawl in Content Sources.

Create the Search REST API URL using querytext, sourceid and refinementfilters query parameters as the query entry point to search for the users whose manager is the given user, and the full URL is

http://server/_api/search/query?querytext='*'&refinementfilters='Manager:equals("domain\\user")'&sourceid='B09A7990-05EA-4AF9-81EF-EDFAB16C4E31'.

Reference - https://social.technet.microsoft.com/Forums/windowsserver/en-US/094d8193-6177-4329-992f-f98f58d40057/forum-faq-how-to-get-the-users-who-report-to-a-given-manager-with-rest-api

Meaning of different query string parameters can be found here: https://blogs.msdn.microsoft.com/nadeemis/2012/08/24/sharepoint-2013-search-rest-api/

  • How to create a managed property in SPO, where we don't have access. Has anyone used Microsoft Graph API, is there any method available in Graph API such that, we can get the reportees' names and store it in an Array. – SaMolPP Jan 26 '18 at 13:51

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.