- 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-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-14-2015 12:39 PM
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';
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2015 05:39 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2015 06:44 AM
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);
}
}