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.

I'd like to do this same thing, not with current user, but rather the "parameterized" user. So, from the URL, I can know the key identifier of the person and can drill down to their chart, but it only shows the one box. I want to drill down to their manager level. I've coded a hidden link to "go up" after the chart loads, but that code does not work reliably.

I guess at simplest, I want to first do a lookup of manager ID based on employee ID and to a drill down to the manager We are currently using a Sharepoint list to populate our chart.

I figured it out. Simple:

var employeeId = GetUrlKeyValue("employeeId");

if (employeeId ) {

// Skip initial rendering to speed up the process
renderer.config.renderInitialNode = false;

// Wait for web part loading
renderer.onInitialLoadingFinished(function() {
renderer.dataProvider.getBoxGroupItemDataById(employeeId, function (dataItem) {
renderer.drilldown(employeeId.ParentId);
}
});
}

1 Like