- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022 12:12 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022 01:59 AM - edited 12-05-2022 02:30 AM
@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
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022 04:37 AM
@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);
}
}
Still visible. What could be the problem?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022 04:39 AM
@JohnDF "ILV" should be in small letters "ilv". That should fix your issue.
g_form.setSectionDisplay('ilv', false);
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022 04:45 AM
@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
ServiceNow Community Rising Star, Class of 2023
