Hiding modules based on Roles

ideamax
Mega Expert

How can I hide modules in the navigation based on Roles?

e.g. I have one module which is available to all users who do not have any roles but that module should not be displayed to specific Role .

Create New
All
My Open Items
My Close Items

If these are the four modules which are available to all employees, but to Special Role only 'All' should be available.

How can we achieve this?

6 REPLIES 6

gaidem
ServiceNow Employee
ServiceNow Employee

Interesting....

Either, create a role and add all those non-role users to that and require the module to have that role. Or, I've never done this, but hide the module via a DOM script within UI Scripts


I would rather adding those non-role users to a new role and require the module to have that role. It will be easier to be maintained in the long run, than introducing an extra custom layer of security.



However, if you really really want to hide the module via a UI script, try this:



/**


* UI Script


*


* Name: HideModulesForRole


* Application: Global


* Global: True


* Active: True


*/




document.observe('dom:loaded', function() {


  // Find the navigator windows


  var nav_window = parent.document.getElementById("gsft_nav").contentWindow;


  var roles = nav_window.NOW.user.roles;




  // Remove the module if roles is admin


  if ('admin' == roles) {


  // module.14641d70c611228501114133b3cc88a1 is the Create Now menu item of the Incident module.


  // You will need to inspect the DOM to find out the menu item ID to remove.


  var menu_item = nav_window.document.getElementById("module.14641d70c611228501114133b3cc88a1");


  if (menu_item) menu_item.parentNode.removeChild(menu_item);


  }


});



It will hide the "Create New" menu item of the Incident module IF you're with admin role.


davida_hughes
ServiceNow Employee
ServiceNow Employee

Right click the module and click "edit module". There should be a field called roles where you can specify which roles you want to see the module. If you don't have the roles field, you need to personalize your form and add it.


Hi Pratik,



Did u able to do this?


I too have similar requierment.


Please let me know how u done this