- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2017 05:24 AM
I have a reference field on sys_user - 'Default Assignment Group'.
I want the lookup list to be filtered so you can only pick groups that the user is member of.
Can anyone give me some input on how to do the script include.
So far my starting point looks like this, but I'm not sure how to asign the current sys_user object to var a.
Anyone?
function u_backfillAssignmentGroup() {
var gp = ' ';
var a = current;
//return everything if the assigned_to value is empty
if(!a)
return;
//sys_user_grmember has the user to group relationship
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('user',a);
grp.query();
while(grp.next()) {
if (gp.length > 0) {
//build a comma separated string of groups if there is more than one
gp += (',' + grp.group);
}
else {
gp = grp.group;
}
}
// return Groups where assigned to is in those groups we use IN for lists
return 'sys_idIN' + gp;
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2017 05:47 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2017 05:46 AM
Instead of current, user gs.getUserByID(); , it will work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2017 05:47 AM
Hi Morte,
Use the below code for reference qualifer
function u_backfillAssignmentGroup() {
var userSysId = gs.getUserID();
var groupSysIdArray = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user',userSysId);
gr.query();
while(gr.next()){
groupSysIdArray.push(gr.group.toString());
}
return "sys_idIN" + groupSysIdArray.join(',').toString();
}
Call the function correctly through reference qualifier. It should return all groups which current logged in user is member of
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2017 05:47 AM
In line 2 use
var a = current.sys_id;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2017 05:54 AM
Thanks - most simple solution, and it worked:)