- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2016 06:10 AM
I am looking to make an advanced reference qualifier for a user reference field. I want it so when a this field is selected, only certain members from a group show up. What would the script method be?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2016 06:26 AM
Hi Josh,
You need to write your own custom script include. I have just created one. Below is the code.
--
var GroupUtil = Class.create();
GroupUtil.prototype = {
initialize: function() {
},
memberofGroup: function(){
var users=[];
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('group','1c590685c0a8018b2a473a7159ff5d9a');
grp.query();
while(grp.next()) {
users.push(grp.getValue('user'));
}
gs.addInfoMessage('sysIDIN'+users.join(','));
return 'sys_idIN'+users.join(',');
},
type: 'GroupUtil'
};
---
Here is the screen
You need to call this from ref qualifier.
javascript:new GroupUtil().memberofGroup()
hope this helps
Cheers
Srini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2016 06:13 AM
I tried the following but it didn't work:
javascript:gs.getUser().isMemberOf('insert group name here');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2016 06:25 AM
This would be a little more complex than that. The reference qualifier is basically a query you're running against the user table, so it has to be formatted in that way. What you'd need to do is write a simple script include that queried the sys_user_grmember table and returned a comma separated list of user sys_ids. You would return something like 'sys_idIN' + listOfSysIDs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2016 06:26 AM
Hi Josh,
You need to write your own custom script include. I have just created one. Below is the code.
--
var GroupUtil = Class.create();
GroupUtil.prototype = {
initialize: function() {
},
memberofGroup: function(){
var users=[];
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('group','1c590685c0a8018b2a473a7159ff5d9a');
grp.query();
while(grp.next()) {
users.push(grp.getValue('user'));
}
gs.addInfoMessage('sysIDIN'+users.join(','));
return 'sys_idIN'+users.join(',');
},
type: 'GroupUtil'
};
---
Here is the screen
You need to call this from ref qualifier.
javascript:new GroupUtil().memberofGroup()
hope this helps
Cheers
Srini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2016 06:52 AM
This looks perfect, Srini! My only question is: could this already exist somewhere by default? I didn't find anything when looking through the baseline Script Includes, but it seems like it would be a common use case that might already be addressed.