Hiding Form Sections Based on User Group

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2014 09:52 AM
I am trying to hide a form section based on a users group, which is not listed on the form itself.
I tried the following client script and it's doesn't hide the tab.
function on Load(){
var me = g_user.userID();
if (me.isMemberOf('7efcb8956fa21100dd3253eabb3ee40c'){
var sections = g_form.getSections();
sections[3].style.display = 'block';
} else {
sections[3].style.display = 'none';
}
}
Any help as to what I can do to get this to work would be appreciated!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2014 12:13 AM
Hi Allison Walker,
You can try out this,
Display Business Rule :-
g_scratchpad.groups = gs.getUser().isMemberOf('7efcb8956fa21100dd3253eabb3ee40c'); // try using Name of the group if the sys_id doesn't work (i tried with the Name of the group and it worked)
Client script :-
function onLoad() {
if(g_scratchpad.groups == false){
var sections = g_form.getSections();
sections[3].style.display = 'none';
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2014 08:16 AM
I was able to resolve this issue. Thanks for your comment though!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2014 06:48 AM
Hi Allison,
Do you recall what you did to resolve the issue?
I'm trying to do the same thing (sorta). Would like to hide a form section based on one or multiple groups or maybe use the group parent field as the trigger.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2015 11:36 AM
New g_form method as per the update on the servicenowguru site. Much easier to us.
g_form.setSectionDisplay('your_section_name_here', false/true);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2016 03:51 PM
Here is one example using a client script:
Name: Hide Governance Section
Table: Change Request [change_request]
Type: onLoad
Global [checked]
Script:
function onLoad() {
try {
var changeMGR = g_user.hasRole('change_mgr');
if (!changeMGR) { //if a user does not have the role, remove governance section
g_form.setSectionDisplay('governance', false);
}
} catch (e) {
console.log('error= ' + e);
}
}