{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":919,"path":"api-reference/server-api-reference/SkillDeterminationUtilsAPI.md","title":"SkillDeterminationUtils - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# SkillDeterminationUtils- Scoped\n\nThe SkillDeterminationUtils script include provides utility methods to get or set work item skill data.\n\nThis script include requires the Skill Determination \\(com.snc.skill\\_determination\\) plugin and is provided within the `sn_skill_rule` namespace.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## SkillDeterminationUtils - SkillDeterminationUtils\\(\\)\n\nConstructor to create an instance of SkillDeterminationUtils.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n```\nvar util = new sn_skill_rule.SkillDeterminationUtils();\n```\n\n## SkillDeterminationUtils - assignSkillsToWorkItem\\(Array skills, GlideRecord now\\_GR\\)\n\nAssigns an array of active skill objects to a work item.\n\n|Name|Type|Description|\n|----|----|-----------|\n|skills|Array|Array of active skill objects to be assigned.|\n|skill.skillName|String|Name of the skill.|\n|skill.skillSysId|String|Sys ID of the skill.|\n|skill.mandatory|Boolean|True if the skill is mandatory, false otherwise.|\n|skill.skillLevelName|String|Optional skill level name.|\n|skill.skillLevelSysId|String|Optional skill level Sys ID.|\n|now\\_GR|GlideRecord|GlideRecord of the work item on which to assign skills.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe examples below create an Interaction record using the table name \\(interaction\\) and show how to assign skills to the interaction work item, creating a record in the Interaction Skills \\[interaction\\_m2m\\_skill\\] table.\n\nUse case 1: Use returned results from determineWorkItemSkills\\(\\) to assign skills to a work item from the Interaction table.\n\n```\n// Create an interaction record\nvar now_GR = new GlideRecord('interaction');\nnow_GR.insert();\n\nvar util = new sn_skill_rule.SkillDeterminationUtils();\n\n// Get interaction skills interaction \n// and specify if any are mandatory\nvar result = util.determineWorkItemSkills(now_GR);\n\n// Assign skills determined by result and \n// assign them to the interaction work item\nutil.assignSkillsToWorkItem(result, now_GR);\n```\n\nUse case 2: Manually insert skills array. In this case, assign IT skills to the Interaction work item.\n\n```\nvar now_GR = new GlideRecord('interaction');\nnow_GR.insert();\n\nvar util = new sn_skill_rule.SkillDeterminationUtils();\n\nvar skills = [{\"skillSysId\":\"2eb1c2029f100200a3bc1471367fcfe4\", \"skillName\":\"IT\", \"mandatory\":true, \"skillLevelName\":\"\", \"skillLevelSysId\":null}];\n\nutil.assignSkillsToWorkItem(skills, now_GR);\n```\n\n## SkillDeterminationUtils - determineWorkItemSkills\\(GlideRecord now\\_GR\\)\n\nGets skills for a specified work item, indicates if the skills are mandatory, and lists any skill levels.\n\n|Name|Type|Description|\n|----|----|-----------|\n|now\\_GR|GlideRecord|GlideRecord of a work item from any interaction or task table extension.|\n\n<table id=\"table_ict_yl5_fhb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nArray\n\n</td><td>\n\nOne or more skill objects.-   skillSysId: String. Sys ID of the skill from the Skills \\[cmn\\_skill\\] table.\n-   skillName: String. Name of the skill.\n-   mandatory: Boolean. True if mandatory, false otherwise.\n-   skillLevelName: If skill exists, name of the skill level.\n-   skillLevelSysId: If skill exists, Sys ID of the skill level from the Skill Levels \\[cmn\\_skill\\_level\\] table.\n\n</td></tr></tbody>\n</table>The following script creates an interaction record, gets skills for the interaction work item, and indicates if the skills are mandatory.\n\n```\n// Create an interaction record\nvar now_GR = new GlideRecord('interaction');\nnow_GR.insert();\n\nvar util = new sn_skill_rule.SkillDeterminationUtils();\n\nvar result = util.determineWorkItemSkills(now_GR);\ngs.info(JSON.stringify(result));\n```\n\nOutput:\n\n```\n[{\"skillSysId\":\"6c0f025c7f672300a8b1bdc8adfa917f\",\n\"skillName\":\"Premier Support Certified\",\n\"mandatory\":false,\"skillLevelName\":\"\",\n\"skillLevelSysId\":null}]\n```\n\n"}}