How to exclude CEO from the employee who doesn't have manager

Our CEO does not have manager in the O365 and Sharepoint. We would like to filter out (in Plumsail's Orgchart while using search tool) any Sharepoint user who don't have manager except our CEO. The Javescript I referred below is from the other topics and modified to achieve the result. It filtering out the users without manager successfully .
However, I get this error message below when I go to the CEO department ; and the root UserName is our CEO's email. Thanks for your help!

function(itemData){
// this user -CEO we need to ignore
var ignoreList = [
'ceo@ourcompany.com'
];
// this will have a value of true if it has manager data
var hasManager = (itemData["Manager"] !== '') ? true : false;
// this returns true if the given userName is not in the ignoreList array
// and the given user has manager data
return (ignoreList.indexOf(itemData['UserName']) < 0 && hasManager) ? true : false;
}

1 Like

Hello @moraj,

The code you provided will only display a user in the Org Chart if their username is not in ignoreList and if they have data in the 'Manager' field. Ignore list in this case works the other way around - as a black list. Even if the user has data in the 'Manager' field, they will not be displayed.

Considering you would also like your CEO to be displayed, the code needs to be modified as follows:

function(itemData){
	// this user -CEO we need to ignore
	var ignoreList = [
		'ceo@ourcompany.com'
	];
  
	var hasManager = itemData["Manager"] !== '';
  	var shouldIgnore = ignoreList.indexOf(itemData['UserName']) > -1;
  
	return shouldIgnore || hasManager;
}

The above code will display either those users whose username is in the ignoreList array (in this case, your CEO) or those users who have manager.

Hope this helps!