- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 02:18 PM
Hi Community, I'm working on a catalog item request with the below requirements. My client script isn't working in the Service Portal and I believe it's because I need to use GlideAjax instead of GlideRecord. I'm on a deadline, so any input would be greatly appreciated. Thank you.
- Show 'Assigned To' variable if logged in user is a member of 'Facilities' group
- Show 'Close Notes' variable if logged in user is a member of 'Facilities' group
- Hide Assigned To and Close Notes variables if logged in user isn't member of Facilities group
onLoad Client Script:
function onLoad() {
var userID = g_user.userID;
if (GetGroupMembers(userID) == true){
g_form.setDisplay('variables.assigned_to', true);
g_form.setDisplay('variables.close_notes', true);
}
else{
g_form.setDisplay('variables.assigned_to',false);
g_form.setDisplay('variables.close_notes', false);
}
}
function GetGroupMembers(user) {
var usrGrp=new GlideRecord("sys_user_grmember");
usrGrp.addQuery('group', '9682088ddb230010df87ab7dca9619cd');
usrGrp.addQuery('user', user);
usrGrp.query();
if(usrGrp.next()){
return true;
}
else {
return false;
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2020 03:29 AM
Hi,
Okay so this is for catalog client script and on the catalog item view while submitting the request; in this case display business rule won't work;
you would require to create script include and use GlideAjax in onload client script
Script Include Below:
var u_userInfoAjax = Class.create();
u_userInfoAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGroupMembership: function(){
var user = gs.getUserID();
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery('group.name', 'Facilities');
gr.addQuery('user', user);
gr.query();
return gr.hasNext();
},
type: 'u_userInfoAjax'
});
Client Script:
function onLoad(){
var ga = new GlideAjax('u_userInfoAjax');
ga.addParam('sysparm_name', "getGroupMembership");
ga.getXMLAnswer(function(answer){
if(answer.toString() == 'true'){
g_form.setDisplay('assigned_to', true);
g_form.setDisplay('close_notes', true);
}
else{
g_form.setDisplay('assigned_to',false);
g_form.setDisplay('close_notes', false);
}
});
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
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-12-2020 04:18 PM
Try below
function onLoad() {
var userID = g_user.userID;
if (GetGroupMembers(userID)){
g_form.setValue('variables.assigned_to', 'true');
g_form.setValue('variables.close_notes', 'true');
}
else{
g_form.setValue('variables.assigned_to','false');
g_form.setValue('variables.close_notes', 'false');
}
}
function GetGroupMembers(user) {
var usrGrp=new GlideRecord("sys_user_grmember");
usrGrp.addQuery('group', 'ad8a2b2bdb77770049cd4b8b0b961971');// Facilities group
usrGrp.addQuery('user', user);
usrGrp.query();
if(usrGrp.next()){
return true;
}
else {
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 07:01 PM
Thanks for the response, but this script didn't work for me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 09:35 PM
Hi,
You can use Display Business rule to check that user is member of Facilities group
g_scratchpad.user =gs.getUser().isMemberOf('Facilities');
And in OnLoad Client Script
if(g_scratchpad.user==true)
{
g_form.setDisplay('assigned_to', true);
g_form.setDisplay('close_notes', true);
}
else
{
g_form.setDisplay('assigned_to', false);
g_form.setDisplay('close_notes', false);
}
Please mark it is Helpful/Correct if it Help you.
Thanks and Regards,
Ankush.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 10:10 PM