Hide menu in service portal for group

ALe1
Tera Contributor

Hello. Pls, How do I hide the visibility of a service portal menu for a certain group?  tks 

1 REPLY 1

Riya Verma
Kilo Sage
Kilo Sage

Hi @ALe1 ,

Hope you are doing great.

 

  1. Navigate to the Service Portal --> "Service Portal" > "Portals" > "Service Portal Configuration."
  2. Identify the specific menu you want to hide for a certain group. Note down the sys_id of that menu, as we'll need it later.
  3. Now, create a new UI Script. UI Scripts allow you to add custom JavaScript code to the Service Portal.
  4. Give the UI Script a meaningful name, such as "Hide Menu for Group."
  5. In the script code section, you'll need to write JavaScript code that checks the current user's group membership and hides the menu if the user belongs to the specified group.

 

// Retrieve the current user's group membership
var groups = gs.getUser().getMyGroups();

// Define the sys_id of the group for which the menu should be hidden
var groupSysID = "ENTER_GROUP_SYS_ID_HERE";

// Check if the current user belongs to the specified group
if (groups.indexOf(groupSysID) !== -1) {
    // Hide the menu by targeting its DOM element
    var menuElement = document.querySelector("ENTER_MENU_SELECTOR_HERE");
    if (menuElement) {
        menuElement.style.display = "none";
    }
}
​

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma