- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2022 11:51 PM
Hi,
I have requirement that there is one catalog item with two variables User and Group. User is of single line text variable and group is reference type variable.
When I click on group search icon, it should display list of only those groups of which currently logged in user is a part but I am getting all groups in the list.
I have created script include for this and calling this script include in the reference qualifier field of group variable of the Catalog item.
I have attached the required screenshots.
Pls help me to find what is wrong with my code.
Below is the script include I have written-
var GetUserGroups = Class.create();
GetUserGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGroups:function(){
var arr=[];
var grp=new GlideRecord('sys_user_group');
grp.addQuery('active',true);
grp.query();
while(grp.next())
{
if(gs.getUser().isMemberOf(grp.name)== true)
{
arr.push(grp.name);
}
}
return arr;
},
type: 'GetUserGroups'
});
Regards,
Afsar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 02:09 AM
Hi
Finally, this will solve your issue:
Update Script Include:
var GetGroupMembers = Class.create();
GetGroupMembers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getMembers: function(userId) {
var groups = [];
var getMyGroup = new GlideRecord('sys_user_grmember');
getMyGroup.addEncodedQuery('user.user_name=' + userId + '');
getMyGroup.query();
while(getMyGroup.next()) {
groups.push(getMyGroup.getValue('group'));
}
//Added log to see what data is generated
//gs.log('[DEBUG] Groups for User ID: ' + userId + '\n' + groups);
if(JSUtil.notNil(groups)) {
return groups.join(',');
} else
return '-1';
},
type: 'GetGroupMembers'
});
Reference Qualifier:
javascript: 'sys_idIN' + new GetGroupMembers().getMembers(current.variables.<backend_name_of_user_variable>);
Check the screenshot as well:
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 06:39 AM
Afsar,
Reference qualifier can be set up on field User to remove himself from the selection.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 04:40 AM
Little bit late because the question has already been answered but in case other user may read this post, I'll add my reply here.
I'll set User type to be a reference to sys_user table as Ankur mentioned.
I'll do it as follows.
1. Field user. Type: reference to "sys_user" table. Default value: "javascript: gs.getUserID();"
2. Field group. Type: reference to "sys_user_group" table.
Reference qualifer:
javascript: 'sys_idIN' + new GetGroupMembers().getMembers(current.variables.user);
Script Include. Note that "Client callable" is unchecked because reference qualifier is executed on server so it's not being called from Client.
var GetGroupMembers = Class.create();
GetGroupMembers.prototype = {
initialize: function() {},
getMembers: function(userId) {
var groups = [];
var getMyGroup = new GlideRecord('sys_user_grmember');
getMyGroup.addQuery('user', userId);
getMyGroup.query();
while (getMyGroup.next()) {
groups.push(getMyGroup.getValue('group'));
}
return groups.join(',');
},
type: 'GetGroupMembers '
};
Execution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 10:48 AM
Hi
Just a point here!
For using Script Include in Reference Qualifier it has to be Client Callable true. Please check the documentation "Script includes" and a screenshot from the same is provided below:
The point to note is the method constructor should be like Server Side as we do not pass parameters over an Ajax Call unlike we just pass parameters in the method invocation.
Thanks and regards,
Kartik