Hide related Links

Dev321
Tera Contributor

I was able to hide the related list on a form view now i need to hide the related Links options for non admin users. Can i configure this on the same client script and if so i dont see an API for this

1 REPLY 1

Riya Verma
Kilo Sage
Kilo Sage

HI @Dev321 ,

 

Hope you are doing great.

 

There is no direct API available to hide these options. Instead, we can use the GlideForm API to customize the form behavior for different user roles. Below is the solution for achieving this:

  1. Create a new client script or edit the existing one that you used to hide the related list on the form view.

  2. Determine the conditions under which you want to hide the related Links options. For instance, you may want to hide them for users who do not have the "admin" role.

  3. Use the GlideForm API to check the user's roles and hide the related Links options if the condition is met. You can use the 'getDisplayValue()' method to get the current user's roles.

Reference code for same :

 

function onLoad() {

  var userRoles = g_form.getDisplayValue('user_roles');

  var allowedRole = 'admin';

  // Check if the current user has the allowed role
  if (userRoles.indexOf(allowedRole) === -1) {
    // Hide the related Links options by targeting the appropriate DOM elements
    hideRelatedLinksOptions();
  }
}

function hideRelatedLinksOptions() {
  // Replace 'related_links_options' with the actual HTML element ID that contains the related Links options
  var relatedLinksOptions = document.getElementById('related_links_options');

  if (relatedLinksOptions) {
    relatedLinksOptions.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