- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2015 12:12 PM
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:
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!
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2015 12:20 PM
I do this:
var sections = g_form.getSections();
if(g_user.hasRole('itil')){
sections[1].style.display = 'block';
}else{
sections[1].style.display = 'none';
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2015 05:34 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2015 05:45 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2015 05:48 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2015 05:49 PM
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';
}
}