- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 01:08 PM - edited 03-24-2025 01:13 PM
Hello ServiceNow Enthusiasts!!
How to restrict the visibility of a mandatory field on a ServiceNow catalog item form for only the members of a given group via client script or UI policy?
So the members of a given group should not be able to see this field on the form but the rest of the organization should be.
All help is greatly appreciated. Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 01:22 PM
Hello @Zubair Alam
Please use below script include -
var CheckUserGroup = Class.create();
CheckUserGroup.prototype = {
initialize: function() {},
isUserInGroup: function() {
var restrictedGroup = 'YOUR_GROUP_SYS_ID'; // Replace with actual sys_id of the restricted group
var userID = gs.getUserID();
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', restrictedGroup);
gr.addQuery('user', userID);
gr.query();
return gr.hasNext(); // Returns true if user is in the group
},
type: 'CheckUserGroup'
};
And below in on load client script -
function onLoad() {
var ga = new GlideAjax('CheckUserGroup');
ga.addParam('sysparm_name', 'isUserInGroup');
ga.getAnswer(function(response) {
if (response === 'true') {
g_form.setDisplay('your_field_name', false); // Hides the field for restricted group
}
});
}
You can replace the script include and function names as per your requirement.
Please let me know via screenshot of stuck anywhere.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 08:49 PM
you can use onLoad client script with GlideAjax
OR
If you don't want to use GlideAjax, script include then do this
1) create that group, give some role to that group so that members get that role
2) in onload check that role and restrict the field
function onLoad() {
if (g_user.hasRoleExactly('role name')) {
g_form.setMandatory('variableName', false);
g_form.setDisplay('variableName', false);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 01:22 PM
Hello @Zubair Alam
Please use below script include -
var CheckUserGroup = Class.create();
CheckUserGroup.prototype = {
initialize: function() {},
isUserInGroup: function() {
var restrictedGroup = 'YOUR_GROUP_SYS_ID'; // Replace with actual sys_id of the restricted group
var userID = gs.getUserID();
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', restrictedGroup);
gr.addQuery('user', userID);
gr.query();
return gr.hasNext(); // Returns true if user is in the group
},
type: 'CheckUserGroup'
};
And below in on load client script -
function onLoad() {
var ga = new GlideAjax('CheckUserGroup');
ga.addParam('sysparm_name', 'isUserInGroup');
ga.getAnswer(function(response) {
if (response === 'true') {
g_form.setDisplay('your_field_name', false); // Hides the field for restricted group
}
});
}
You can replace the script include and function names as per your requirement.
Please let me know via screenshot of stuck anywhere.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 08:49 PM
you can use onLoad client script with GlideAjax
OR
If you don't want to use GlideAjax, script include then do this
1) create that group, give some role to that group so that members get that role
2) in onload check that role and restrict the field
function onLoad() {
if (g_user.hasRoleExactly('role name')) {
g_form.setMandatory('variableName', false);
g_form.setDisplay('variableName', false);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 01:58 PM - edited 04-01-2025 01:58 PM
Thanks @Ankur Bawiskar
Much appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 08:54 PM
Hello @Zubair Alam
Please confirm if you checked my answer. Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for my efforts and also it can move from unsolved bucket to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeE