Hide tabs based on current role

Wade Clairmont
Tera Guru

Hey there,

I know there are some articles out there that review this, however, after a bit of time attempting each version, I need your help!

I need to hide form section tabs based on role:

hide tabs.jpg

I have created a script "onload" to do this, but hence my question....... what am I missing?

function onLoad() {

  var VIPAction = g_user.hasRole('u_vip_action_user');

  var sections = g_form.getSections();

  if(VIPAction) {

  g_form.setSectionDisplay(sections[2], true);

  g_form.setSectionDisplay(sections[3], true);

  }

  else {

  g_form.setSectionDisplay(sections[2], false);

  g_form.setSectionDisplay(sections[3], false);

  }

}

Thanks in advance!

1 ACCEPTED SOLUTION

Mike Allen
Mega Sage

I do this:



var sections = g_form.getSections();



if(g_user.hasRole('itil')){


        sections[1].style.display = 'block';


}else{


        sections[1].style.display = 'none';


}


View solution in original post

8 REPLIES 8

Is the onload script actually running through to competition?


Try throwing in some alert('here') into both if branches to see if the code is reaching those lines.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

uluerje
Mega Expert

I'd just set up another view without the tabs and then force users who have that role to go to the new view.   You could easily modify the business rule at the following link to do that - Restrict Form Views by Role - ServiceNow Wiki


I feel it is always better to do as much processing server side if you can.


This is the best solution



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

khabibulan72
Kilo Expert

I've had some luck setting up an onDisplay business rule to get the current user roles, then have your client script evaluate the results from scratchpad.


function onLoad() {



  if(g_scratchpad.groups==false){


  var sections = g_form.getSections();


  sections[4].style.display = 'none';


  }


}