- 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-19-2022 11:55 PM
Hi
Could you please provide the Script Include in the question itself?
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 12:00 AM
Added
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 12:05 AM
Hi
Thanks for providing the script. Please find the updated script below:
Script Include:
var GetGroupMembers = Class.create();
GetGroupMembers.prototype = {
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('sys_id'));
}
if(groups) {
return groups.join(',');
} else
return '-1';
},
type: 'GetGroupMembers'
};
Screenshot:
You also need to have changes in your Reference Qualifier as provided below:
javascript: new GetGroupMembers().getMember(current.<variable_name>)
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 12:32 AM
Hi
Are you still facing the issue?
If my answer solved your issue then please mark my answer as correct/helpful, so that other community members may get a solution if they face a similar issue!
Thanks and regards,
Kartik