One level up manager and one level down for subordinates in search results?

How do I get one level up with manager and one level down for subordinates in search results?

I found this page which gives only one level up with manager only but I need sub-ordinates too.
Any help is appreciated. Thanks.

This is a solution for Org Chart 3. Check the reply for Org Chart 4 below.

Hello, @vijibhas

You can use the following code. As usual, JS methods and events are gotten from this article of documentation. The code works a bit slow so an item that should be hidden pops up for a second.

//When search results are rendered
renderer.onSearchResultRendered(
    function(event, searchResult, itemData){
        //Get current user
        renderer.dataProvider.getCurrentUserAccountName(function (accountName) {
            //Get an object with data of the current user
            renderer.dataProvider.getBoxGroupItemDataById(accountName, function (dataItem) {
                //Change style if it is not the current user or it has not the current user as a manager or it is not the manager of the current user
                if(!(itemData.AccountName == dataItem.Id || itemData.Manager == dataItem.Id || itemData.AccountName == dataItem.ParentId)){
                    searchResult.$elem.css({ 'display': 'none' });
                }
            });
        });     
    }
);

With the code, I tried but I didn't get sub-ordinates for search result.
Attached the image in which I am expecting. Please do help. Thanks.

@Evgeniy Please do help me in resolving this. Thank you.

Hi @vijibhas!
We're currently deciding on the best way to achieve this. I'll get back to you when I have the results.

This is a solution for Org Chart 3. Check the reply for Org Chart 4 below.

@vijibhas,
Please try the following:

// function to expand the items for 2 levels based on condition
function expand(item){
    renderer.showLoadingPanel();
    renderer.expandNodeLevelsConditionally(3, 
	function (itemData) {
       // check if the box contains the found person or his or her manager
        return itemData.AccountName == item.Properties.Manager || itemData.AccountName == item.Id;       
    }, function () {        
        renderer.hideLoadingPanel();
    });
}

  // when the search result is clicked:
 renderer.searchResultClickedAction = function (itemId) {
    renderer.dataProvider.getBoxGroupItemDataById(itemId, function (item) {
        // drill down to the manager of the found person and call the expand function
        renderer._orgChartControl.drillDownById(item.ParentId).then( 
        function() {
          expand(item);
        });
    }); 
  }

Update for Org Chart 4.

// Variable to distingush the drill-down from search and from chart
let drilledFromSearch = false;
//Variable to save the clicked person
let clickedPersonData;

// Function to expand the items for two levels based on condition
function expand(item) {
    api.showLoadingPanel();
    api.expandNodeLevelsConditionally(3,
        function (itemData) {
            // Check if the box contains the found person or the person's manager
            return itemData.AccountName == item.parentId || itemData.AccountName == item.id;
        },
        function () {
            api.hideLoadingPanel();
        });
}

// When the search result is clicked
api.searchResultClickedAction = function (itemId) {
    api.dataProvider.getBoxGroupItemDataById(itemId, function (item) {
        // The drill-down is from search
        drilledFromSearch = true;
        // Save the data of the clicked person
        clickedPersonData = item;
        // Drill down to the manager of the found person
        api.drillDown(item.parentId.split("|").pop());
    });
}

api.onDrilledDown(() => {
    // If the drill-down was from search
    if (drilledFromSearch) {
        // Execute the 'expand' function
        expand(clickedPersonData);
    }
    // Set the drill-down switcher to 'false'
    drilledFromSearch = false;
});