- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 09:32 AM
Hello all,
I have created a new reference field on the sys_user table and I want to create a reference qualifier that would only show active groups to which the given user is assigned to. Any idea how to achieve this? Thank you
For example, as a system admin I want to assign a primary group to Abel Tuter, but it needs to be active group to which he is assigned to.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 10:24 AM
Actually, if you're looking for a reference to the Group, which I assume you are, you may want to created a Script Include that builds a query string for you of all the sys_ids of the group the user is a member of.
var UserRefQual = Class.create();
UserRefQual.prototype = {
initialize: function() {},
getGroups: function(user) {
var groups = [];
var grUserGrp = new GlideRecord('sys_user_grmember');
grUserGrp.addQuery('user', user.sys_id);
grUserGrp.query();
while (grUserGrp.next())
{
groups.push(grUserGrp.group);
}
gs.info("sys_idIN" + groups);
return "sys_idIN" + groups;
},
type: 'UserRefQual'
};
And in your reference qualifier, you can use this:
javascript: new global.UserRefQual().getGroups(current);
Make sure you change your reference field to Group. You won't have to worry about display values that way.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 10:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 10:15 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 10:24 AM
Actually, if you're looking for a reference to the Group, which I assume you are, you may want to created a Script Include that builds a query string for you of all the sys_ids of the group the user is a member of.
var UserRefQual = Class.create();
UserRefQual.prototype = {
initialize: function() {},
getGroups: function(user) {
var groups = [];
var grUserGrp = new GlideRecord('sys_user_grmember');
grUserGrp.addQuery('user', user.sys_id);
grUserGrp.query();
while (grUserGrp.next())
{
groups.push(grUserGrp.group);
}
gs.info("sys_idIN" + groups);
return "sys_idIN" + groups;
},
type: 'UserRefQual'
};
And in your reference qualifier, you can use this:
javascript: new global.UserRefQual().getGroups(current);
Make sure you change your reference field to Group. You won't have to worry about display values that way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 10:38 AM
Hello
thanks a lot. This works, however, how can I add a qualifier to also filter active groups? Thank you