Constrain the assignment group field

This example shows how to use JavaScript and a script include to restrict the incident Assignment group choices to only the groups that contain the user specified in the Assigned to field.

Before you begin

Role required: personalize_dictionary or admin

Procedure

  1. Open an incident.
  2. Right-click the Assignment group field and select Configure Dictionary.
  3. If the form appears in Default view, click Advanced view under Related links.
  4. In the Use reference qualifier field, ensure that the Advanced option is selected.
  5. In the Reference qual field, enter javascript:new BackfillAssignmentGroup().BackfillAssignmentGroup().
  6. Save the record.
  7. Navigate to System Definitions > Script Includes.
  8. Click New.
  9. Create a script include with the following JavaScript code. Ensure that the Client callable option is selected and that the Accessible form field is properly set for the environment.
    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'
    }

What to do next

To test, create an incident and select a user in the Assigned to field. Click the Assignment group lookup icon. Only the groups that contain the user you selected appear. For example, you assign an incident to Bob Smith, who belongs to the Database group and the Networking group. The only options that appear in the assignment group are Database and Networking.