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
05-11-2017 04:32 AM
Hi Allison,
you can use the methods provided on wiki to hide the sections like
if (g_user.hasRole("Some Role")) {
g_form.setSectionDisplay('communication', false);
g_form.setSectionDisplay('availability', false);
}
here communication and availabiltiy are the section names.
Please mark my answer as correct if you find it correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2022 10:46 AM
Please use the below script to achieve your requirement
Script Include:
var getGroupDetails = Class.create();
getGroupDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserMembership: function() {
if (gs.getUser().isMemberOf('sys_id')) //sys_id of the group
return "hide";
else return "no-hide";
},
type: 'getGroupDetails'
});
Client Script:
function onLoad() {
var assetGA = new GlideAjax("getGroupDetails");
assetGA.addParam("sysparm_name", 'getUserMembership');
assetGA.getXML(assetSectionDisplayResponse);
function assetSectionDisplayResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'hide') {
g_form.setSectionDisplay('section_name', false); //section name
}
}
}