- 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:48 AM
Do you mean you have a field on the user table, that has groups in (like a glidelist perhaps?) and you wish for only those to be returned when THAT user is selected in the "assigned to" field of the ticket? because the query above (if a = current.assigned_to;) perhaps, would return the groups the user is a member of.
If you have a field on the user table, storing the groups they are a member of (Not recommended and not very useful) then you could just return that instead as below perhaps?
//untested, coded on the fly in this chat window.... may have some typos
function getMyUserGroups (usrSys) {
var gr = new GlideRecord("sys_user");
usrSys = usrSys || getUserID();
gr.get(usrSys);
if (gr.next()) {
return 'return 'sys_idIN' + gr.myWierdFieldContainingGroups;
}
}
Hope this helps, we can definitely get a solution once we clarify the above
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2017 06:23 AM
Hi ,
It will benefit other community members so i am putting rectification to it . In first place this solution is wrong :
var a = current.sys_id; as it will give the sys_id for the whole record itself ( for instance incident in this case ) . Please use :
var a = current.assigned_to; // assigned_to is a reference field on incident and will give sysid for user in the field . Here is the complete working solution for the issue
Ref qualifier on assignment group : javascript:BackfillAssignmentGroup();
Script include :
function BackfillAssignmentGroup()
{
var gp = ' ';
var a = current.assigned_to; // assigned_to is a reference field on incident and will give sysid for user in the field
//var a = gs.getUserID();
// gs.addInfoMessage('This is the assigned to user:' + a );
//var a = current.sys_id;
//var a = gs.getUserID();
//alert ('a');
//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);
// gs.addInfoMessage('These are users groups in which he is the member:' + gp );
}
else {
gp = grp.group;
}
}
// return Groups where assigned to is in those groups we use IN for lists
return 'sys_idIN' + gp;
}
Mark it as correct if this helps you in your code journey!