Filter Assignment Group based on Assigned To

Tanuj
Kilo Contributor

filter assignment group based on assign to in ServiceNow - on the basis of assigned to , i can get the assignment group but i have tree picker attribute on assignment group reference field, which restrict me to show parent assignment group.

 

For eg - if i am part of xyz group and there is no parent group. then i will able to see it well.

Bt xyz group has abc parent group, then i wont be able to see it .

 

Can anyone help me on this, its quite simple but i couldn't figure it out.

3 REPLIES 3

p t1
Kilo Sage

Hi,

 Write advanced  reference qualifier..

when you select assigned to person assignment groups are going to display.

 

var BackfillAssignmentGroup = Class.create();
BackfillAssignmentGroup.prototype = {
initialize: function() {
},

BackfillAssignmentGroup:function() {
var gp = ' ';
var a = current.assigned_to;

//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;
},
type: 'BackfillAssignmentGroup'

 

call this script include in advanced refernce qualifier.

 

javascript:new BackfillAssignmentGroup().BackfillAssignmentGroup()

 

Thanks

 

Hi Preethi,

    Your reference qualifier and script include works perfectly!  Thank you very much.  One thing that I need different is to only pull groups that where Active is True & Hidden is False ('group.active=true^group.u_hidden=false') when the Assigned to is empty.  I've updated your code as below, but when there isn't an assigned to (new record), and I click the Assignment group lookup, it doesn't show any groups at all.  If there is an assigned to, the script works perfectly by looking up that person's group.

 

var BackfillAssignmentGroup = Class.create();
BackfillAssignmentGroup.prototype = {
    initialize: function() {},

    BackfillAssignmentGroup: function() {
        var gp = ' ';
        var a = current.assigned_to;

        //return everything if the assigned_to value is empty
        if (a == '') {
            var gps = new GlideRecord("sys_user_group");
            gps.addEncodedQuery('active=true^u_hidden=false');
            gps.query();
            while (gps.next()) {
                //build a comma separated string of gps if there is more than one
                gp += (',' + gps.group);
            }
        }

        //sys_user_grmember has the user to group relationship
        var grp = new GlideRecord("sys_user_grmember");
        grp.addQuery("user", a);
        grp.addEncodedQuery('group.active=true^group.u_hidden=false');
        grp.query();
        while (grp.next()) {
            if (gp.length > 0) {
                //build a comma separated string of gps 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;
    },
    type: 'BackfillAssignmentGroup'
};

 

Thank you!

Shane

Josh_Cooper
Tera Contributor

You're my hero, this is an epic add.  Thank you!