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

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';


}


No go.   Still shows tabs, however, the list no longer permits the user to add another row, and shows rows removed by security message.


Current script:


function onLoad() {



  var sections = g_form.getSections();



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


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


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


  }else{


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


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


  }


}


The SN Nerd
Giga Sage
Giga Sage

Have you considered using this API instead?



14.7 setSectionDisplay

boolean setSectionDisplay(sectionName, display)


Parameters:
sectionName - name of the section to be shown or hidden. The section name is lower case with an underscore replacing the first space in the name, and with the remaining spaces being removed, for example "Section Four is Here" becomes "section_fourishere". Section names can be found by using the getSectionNames method.
display - set true to show, false to hide.
Returns:
Boolean - true if successful.

Also. are you sure your sections are 2 and 3 in the array?



Arrays start at 0.


Try 0 and 1?



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

Yes tried this as well.



function onLoad() {


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



  var sections = g_form.getSectionNames();


  if(VIPAction) {


  g_form.setSectionDisplay('vip_actions', true);


  g_form.setSectionDisplay('verification', true);


  }


  else {


  g_form.setSectionDisplay('vip_actions', false);


  g_form.setSectionDisplay('verification', false);


  }


}