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.
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",
};