Set form section only for specific group readonly

JohnDF
Mega Sage

Hi everyone,

 

my requirement is that only one specific group has readonly access on a form section and the fields on this section. How this possible to hide the section or the fields for all other users except the users in the specific group. Its about 20 fields on the form.

 

Thanks for your help.

1 ACCEPTED SOLUTION

jaheerhattiwale
Mega Sage

@JohnDF Tried and tested solution. Make use of GlideAjax to find out if the logged in user is member of that specific group or not.

 

1. Create a onload client script

Code:

function onLoad() {
var ga = new GlideAjax('UserAjaxUtil'); //UserAjaxUtil is a client callable script include, you can create new or use existing one
ga.addParam('sysparm_name', 'isUserMemberOfGroup');
ga.getXML(hideSection);
}

function hideSection(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");

//If user is not member of group then hide section
if(answer == "false"){
g_form.setSectionDisplay('notes', false);
}
}

 

2. Create or use existing client callable script include

Code:

var UserAjaxUtil = Class.create();
UserAjaxUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {

isUserMemberOfGroup: function(){
return gs.getUser().isMemberOf("<GROUP NAME HERE>");
},

type: 'UserAjaxUtil'
});

 

Please mark as correct answer if this solves your issue

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

7 REPLIES 7

@jaheerhattiwale thanks for reply,

 

thts sound interessting. 

 

What is in my code the problem? Still all user can see the section.

 

var ITcheckUserGroup = Class.create();
ITcheckUserGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	isUserMemberOfGroup: function(){
return gs.getUser().isMemberOf("SLIR_Bearbeiter.SN");
},
    type: 'ITcheckUserGroup'
});

Client callable script incude

 

And here the client script:

function onLoad() {
var ga = new GlideAjax('ITcheckUserGroup'); //is a client callable script include, you can create new or use existing one
ga.addParam('sysparm_name', 'isUserMemberOfGroup');
ga.getXML(hideSection);
}

function hideSection(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");

//If user is not member of group then hide section
if(answer == "false"){
g_form.setSectionDisplay('ILV', false);
}
}

 

JohnDF_0-1670243826995.png

 

Still visible. What could be the problem?

@JohnDF "ILV" should be in small letters "ilv". That should fix your issue.

 

g_form.setSectionDisplay('ilv', false);
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@JohnDF The section should be as forllows in g_form.setSectionDisplay() function:

 

If section name is ILV the the above function expects ilv

If section name is "ILV Section" the the above function expectes ilv_section

 

Space will ve replaced with _ and capital letter to small letter

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023