- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 08:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 08:45 AM
Hello @Venkat141
1. Onload Client Script:
function onLoad() {
var sysid = g_user.userID; //get current user sysid
var ga = new GlideAjax('global.CheckuserGroup'); //script include name
ga.addParam('sysparm_name', 'getgroup'); //function name
ga.addParam('sysparm_name_sysid', sysid); //passing sysid to server
ga.getXMLAnswer(getGroup);
function getGroup(response) {
if (response == 'true') {
g_form.addInfoMessage('Part of group');
} else {
g_form.addInfoMessage('Not Part of group');
}
}
}
2. Script Include:
var CheckuserGroup = Class.create();
CheckuserGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getgroup: function() {
var usersysid = this.getParameter('sysparm_name_sysid');//getting usersysid from client
var mem = new GlideRecord("sys_user_grmember");
mem.addQuery('user', usersysid); //filtering current user
mem.addQuery('group', '8a4dde73c6112278017a6a4baf547aa7'); //add group sysid
mem.query();
if (mem.next()) {
return true;
} else {
return false;
}
},
type: 'CheckuserGroup'
});
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 08:45 AM
Hello @Venkat141
1. Onload Client Script:
function onLoad() {
var sysid = g_user.userID; //get current user sysid
var ga = new GlideAjax('global.CheckuserGroup'); //script include name
ga.addParam('sysparm_name', 'getgroup'); //function name
ga.addParam('sysparm_name_sysid', sysid); //passing sysid to server
ga.getXMLAnswer(getGroup);
function getGroup(response) {
if (response == 'true') {
g_form.addInfoMessage('Part of group');
} else {
g_form.addInfoMessage('Not Part of group');
}
}
}
2. Script Include:
var CheckuserGroup = Class.create();
CheckuserGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getgroup: function() {
var usersysid = this.getParameter('sysparm_name_sysid');//getting usersysid from client
var mem = new GlideRecord("sys_user_grmember");
mem.addQuery('user', usersysid); //filtering current user
mem.addQuery('group', '8a4dde73c6112278017a6a4baf547aa7'); //add group sysid
mem.query();
if (mem.next()) {
return true;
} else {
return false;
}
},
type: 'CheckuserGroup'
});
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 08:55 AM
Hi @Venkat141
1. Create Client callable script include
checkGroupMembership : function(){
var result = gs.getUser().isMemberOf('group_name');
return result; //will be true/false
},
2. Client script
var ga = new GlideAjax('script_include');
ga.addParam('sysparm_name', 'checkGroupMembership'); //function name
ga.getXMLAnswer(callBack);
function callBack(answer){
if(answer == true) {
//is member of group
}else {
//not an member
}
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
