How to drill down to the current user's manager with expand

Hi,
I would be nice to be able to not only drill down to the current user, but to the manager of the current user. The reason is, that if the current user is hierarchically at lowest position, only its box is rendered and it would be nice to see at least one level above and the corresponding peers.

Is there a way for this requirement? We’re using the profile service as data source.

Thanks & Regards
Nicolas

Hi,

You can try to use this function to get current users data:

var isInitialLoad = true;
 
renderer.onLoadingFinished(function(){ 
 if(isInitialLoad){ 
   isInitialLoad = false; 
   
   renderer.dataProvider.getBoxGroupItemDataById(_spPageContextInfo.userLoginName, function(dataItem){
     renderer.drillDown(dataItem.ParentId);
   });
   
 } 
});

Then user ParentId (manager id) to drill down.

See description of this method in the documentation.

And this is implementation for SharePoint 2010:

var isInitialLoad = true;
var $ = Plumsail.OrgChart.jQuery;
var itemDataDeferr = $.Deferred();

var clientContext = SP.ClientContext.get_current();
var currentUser = clientContext.get_web().get_currentUser();
clientContext.load(currentUser);
clientContext.executeQueryAsync(function(){

  var currentUserLogin = currentUser.get_loginName();     
  renderer.dataProvider.getBoxGroupItemDataById(currentUserLogin, function(dataItem){
    itemDataDeferr.resolve(dataItem);
  });

}); 

renderer.onLoadingFinished(function(){   
  if(isInitialLoad){
    isInitialLoad = false;     

    itemDataDeferr.done(function(dataItem){
      renderer.drillDown(dataItem.ParentId);    
    });    
  }
}); 

Best regards
Anton Khritonenkov

Thank you very much, works like a charm.

Regards
Nicolas

Any suggestions for SharePoint Online Modern pages? _spPageContextInfo isn’t available by default.

Hi @bhawthorne,

You are right, it is not available on “Modern” pages.

You should use this function to get current user instead:

renderer.dataProvider.getCurrentUserAccountName(function(accountName){
    //Use accountName here
})

And this is complete code snippet for the case described in my previous message.

var isInitialLoad = true;

renderer.onLoadingFinished(function () {
    if (isInitialLoad) {
        isInitialLoad = false;

        renderer.dataProvider.getCurrentUserAccountName(function (accountName) {
            renderer.dataProvider.getBoxGroupItemDataById(accountName, function (dataItem) {
                renderer.drillDown(dataItem.ParentId);
            });
        });

    }
});

@antonkhrit When I drilldown how can I get upto two levels with expand.

Like current user with manager at top and two levels sub-ordinates at down.