ServiceNow Advanced Reference Qualifier | How to filter the Assignment group based on Assigned To

https://youtu.be/p_1oOjahLy0

Been in a predicament in ServiceNow, where you know the person a task needs to be assigned to, but don’t know the right group? I got you!

In this video, we add an advanced reference qualifier on a dictionary override on the assignment group fields (for incidents) that calls a server side script include to run some funky glideRecord queries and return as back a refined list of group sys_id’s. Its then these groups that are shown when you click the Assignment Group magnifying glass.

https://docs.servicenow.com/en-US/bundle/tokyo-platform-administration/page/script/server-scripting/concept/c_ReferenceQualifiers.html

https://www.servicenow.com/community/developer-forum/dynamic-advanced-reference-qualifier-examples/m-p/1386576

Reference Qualifier bit:

javascript:new global.AssignmentGroupFilter().refineAssignmentGroup(current.assigned_to)

Script Include:

var AssignmentGroupFilter = Class.create();
AssignmentGroupFilter.prototype = {

        initialize: function() {},


        refineAssignmentGroup: function(assigned_to) {
            var groupsArray = [];

            //return all relevant groups (active, itil) if the assigned_to value is empty
            if (gs.nil(assigned_to)) {
	
                var groups = new GlideRecord("sys_user_group");
                groups.addActiveQuery();
                groups.addEncodedQuery('typeLIKE1cb8ab9bff500200158bffffffffff62');
                groups.query();

                if (groups.hasNext) {
                    while (groups.next()) {
                        groupsArray.push(groups.getUniqueValue());
                    }

                } 
				}else {

                    //sys_user_grmember has the user to group relationship
                    var grpMember = new GlideRecord("sys_user_grmember");
                    grpMember.addQuery('user', assigned_to);
                    grpMember.addEncodedQuery('group.typeLIKE1cb8ab9bff500200158bffffffffff62');
                    grpMember.query();

                    if (grpMember.hasNext()) {
					
                        while (grpMember.next()) {
                            groupsArray.push(grpMember.group.toString());
                        }
                    }
                }

                return "sys_idIN" + groupsArray.join(',');
		},

            type: "AssignmentGroupFilter",
        };
Share

You may also like...