Employee Center Menu Item show only to people with direct reports

CCSF-Syd
Tera Expert

We use the Advanced Portal Navigation in Employee Center and we would like to conditionally show menu items only to managers (which we define as people who have direct reports) - is there a way to use the Menu Item "Condition" field to do this?

 

Thank you!

3 REPLIES 3

satyaprakas
Tera Expert

Hi @CCSF-Syd ,

You can create a script include where you can check if user is a manager. Then you can call that script include from the condition field.

 

 

Sample Script include code - 

 

var UserManagerUtils = Class.create();
UserManagerUtils.prototype = {
initialize: function() {},

 

/*
* Check if the logged-in user is a manager based on the 'manager' field in the sys_user table.
* @returns {boolean} - True if the user is a manager, false otherwise.
*/
isManagerByHierarchy: function() {
var userSysId = gs.getUserID();
var gr = new GlideRecord('sys_user');
if (gr.get(userSysId)) {
// Check if the user has direct reports (is a manager)
var directReports = new GlideRecord('sys_user');
directReports.addQuery('manager', userSysId);
directReports.query();
return directReports.hasNext();
}
return false;
},

type: 'UserManagerUtils'
};

 

Call the script include using below code in the condition field

 

javascript: new UserManagerUtils().isManagerByHierarchy();

 

If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

 

Regards,

Satya

Got it, that's helpful. Is there no OOB way to check if someone is a Manager? How does Manager Hub do it I wonder

Sajal Gupta
ServiceNow Employee
ServiceNow Employee

@CCSF-Syd 

Do you use "Manager Hub" on Employee Center, If yes then you can use the gs.hasRole('sn_mh.manager_hub_user') in the condition of Menu Items.

SajalGupta_0-1740633106076.png

 



If not then you can create a new role which would help you check if a person is manager or not and assign it to users with direct reports via a scheduled job or manually and still use a gs.hasRole('your_created_role') in menu item condition.

Regards

Sajal