{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":39806,"path":"platform-administration/t_ExJSConstrainAssignmentGroupField.md","title":"Constrain the assignment group field","bundle":null,"doc_type":null,"release":"australia","body":"\n# Constrain the assignment group field\n\nThis example shows how to use an advanced reference qualifier with 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.\n\n## Before you begin\n\nRole required: personalize\\_dictionary or admin\n\n## Procedure\n\n1.  Open an incident.\n\n2.  Right-click the **Assignment group** label and select **Configure Dictionary**.\n\n3.  If the form appears in **Default view**, under **Related Links**, click **Advanced view**.\n\n4.  In the **Use reference qualifier** field, ensure that the **Advanced** option is selected.\n\n5.  In the **Reference qual** field, enter `javascript:new ReferenceQualifierHelper().backfillAssignmentGroup()`.\n\n6.  Save the record.\n\n7.  Navigate to **System Definitions** &gt; **Script Includes**.\n\n8.  Click **New**.\n\n9.  Name your script includes as `ReferenceQualifierHelper` to match the Javascript in the following step.\n\n    This name ensures the API Name is generated correctly, based on the Name field.\n\n10. [Script includes](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/scripts/c_ScriptIncludes.md) with the following JavaScript code.\n\n    Ensure that the **Accessible form** field is properly set for the environment.\n\n    ```\n    var ReferenceQualifierHelper = Class.create();\n    ReferenceQualifierHelper.prototype = {\n    \t\n    \tbackfillAssignmentGroup:function() {\n    \t\tvar assigneeGroupsQualifier = '';\n    \t\tvar assignee = current.assigned_to;\n    \t\t\n    \t\t//return if the assigned_to value is empty (this causes all groups to be returned)\n    \t\tif(!assignee)\n    \t\t\treturn;\n    \t\t\n    \t\t//sys_user_grmember has the user to group relationship\n    \t\tvar grAssigneeGroups = new GlideRecord('sys_user_grmember');\n    \t\t\n    \t\tgrAssigneeGroups.addQuery('user',assignee);\n    \t\tgrAssigneeGroups.query();\n    \t\t\n    \t\twhile(grAssigneeGroups.next()) {\n    \t\t\tif (assigneeGroupsQualifier.length == 0) {\n    \t\t\t\t// Create the beginning of the qualifier and add the 1st group\n    \t\t\t\tassigneeGroupsQualifier = 'sys_idIN' + grAssigneeGroups.getValue('group');\n    \t\t\t}\n    \t\t\telse {\n    \t\t\t\t// build a comma separated string of groups if there is more than one\n    \t\t\t\tassigneeGroupsQualifier += (',' + grAssigneeGroups.group);\n    \t\t\t}\n    \t\t}\n    \t\t// return Groups where assigned to is in those groups we use IN for lists\n    \t\t\n    \t\tgs.log('DP: RefQual = ' + assigneeGroupsQualifier);\n    \t\t\n    \t\treturn assigneeGroupsQualifier;\n    \t},\n    \ttype: 'ReferenceQualifierHelper'\n    };\n    \n    ```\n\n\n## What to do next\n\nTo 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**.\n\n"}}