{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":39807,"path":"platform-administration/t_ExJavaScriptLimitAssignedToField.md","title":"Constrain the assigned to field by role","bundle":null,"doc_type":null,"release":"australia","body":"\n# Constrain the assigned to field by role\n\nThis example shows how to use JavaScript and a business rule to restrict the incident **Assigned to** field choices to only the users with the itil\\_admin role.\n\n## Before you begin\n\nRole required: personalize\\_dictionary or admin\n\n## About this task\n\nYou can also change itil\\_admin to any other role on a reference field that refers to the User \\[sys\\_user\\] table.\n\n## Procedure\n\n1.  Open an incident.\n\n2.  In the upper-left corner of the screen, click the form context menu, and then select **Configure** &gt; **Dictionary**.\n\n3.  In the **Reference qual** field, enter `javascript:\"sys_idIN\"+getRoledUsers(\"itil_admin\").join(\",\")`.\n\n4.  Save the record.\n\n5.  To see the base system business rule that this JavaScript code calls, navigate to **System Definition** &gt; **Business Rules**.\n\n6.  Open **getRoledUsers**.\n\n    The business rule uses the following JavaScript code.\n\n    ```\n    // Return an array of sys_ids of the users that have at least one role\n    // optional parameters allow the exclusion (NOT IN) of some roles or\n    // look for specific roles (IN)\n    //\n    // optional: queryCondition - 'IN' or 'NOT IN'\n    // optional: roleList - a comma separated list of role names\n    //\n    function getRoledUsers(queryCondition, roleList) {\n       var roleListIds;\n       if (queryCondition && roleList) {\n          roleListIds = getRoleListIds(roleList);\n       }\n    \n       var users = {};\n       var now_GR = new GlideRecord('sys_user_has_role');\n       if (roleListIds) {\n          now_GR.addQuery('role', queryCondition, roleListIds);\n       }\n       now_GR.query();\n       while (now_GR.next()) {\n          users[now_GR.user.toString()] = true;\n       }\n       \n       var ids = [];\n       for (var id in users)\n          ids.push(id);\n          \n       return ids;\n    }\n    \n    // get sys_id's for the named roles\n    function getRoleListIds(roleList) {\n       var ids = [];\n       var now_GR = new GlideRecord('sys_user_role');\n       now_GR.addQuery('name','IN',roleList);\n       now_GR.query();\n       while (now_GR.next()) {\n          ids.push(now_GR.sys_id.toString());\n       }\n       return ids;\n    }\n    ```\n\n\n"}}