{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":712,"path":"api-reference/server-api-reference/CMDBDuplicateTemplateUtilAPI.md","title":"CMDBDuplicateTemplateUtil - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# CMDBDuplicateTemplateUtil- Global\n\nThe CMDBDuplicateTemplateUtil script include provides methods to add and remove de-duplication tasks to/from a de-duplication template.\n\nFor more information on de-duplication of CIs, de-duplication tasks, and de-duplication templates, see [Duplicate CIs remediation](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/de-duplication-tasks.md).\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## CMDBDuplicateTemplateUtils - CMDBDuplicateTemplateUtils\\(\\)\n\nCreates an instance of the CMDBDuplicateTemplateUtils class.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| ||\n\nThe following code example shows how to call this method to create a CMDBDuplicateTemplateUtils object.\n\n```\n\nvar dupTemp = new CMDBDuplicateTemplateUtils();\n```\n\n## CMDBDuplicateTemplateUtils - addTasksToTemplate\\(String templateId, Array taskIds\\)\n\nAdds one or more de-duplication tasks to a specified de-duplication template.\n\nThis method overwrites any existing template values, but logs the previous values for each template in the system logs.\n\nThe following list describes scenarios where a task isn’t added to a template and is then marked as either skipped or failed:\n\n-   The specified template isn’t in the published state. All tasks are marked as skipped.\n-   The specified template is running. All tasks are marked as skipped.\n-   The task isn’t in the open state. The task is marked as skipped.\n-   The task isn’t compatible with the specified template. For example, the specified template might be created for Application Server Tomcat, but the specified de-duplication task is created for Linux Server. The task is marked as skipped.\n-   The specified template doesn’t exist. All tasks are marked as failed.\n-   The GlideRecord update for the template column on the task fails. The task is marked as failed.\n\n|Name|Type|Description|\n|----|----|-----------|\n|templateId|String|Sys\\_id of the de-duplication template to associate with the de-duplication task.|\n|taskIds|Array|List of sys\\_ids of the de-duplication tasks to associate with the specified template.|\n\n<table id=\"table_uch_4y5_xxb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nResult object containing the status of all the tasks that were attempted to be associated with the specified template.Data type: Object\n\n```\n{\n  \"failed\": [Array],\n  \"skipped\": [Array],\n  \"success\": [Array],\n  \"summary\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\nfailed\n\n</td><td>\n\nList of tasks that failed to be associated with the template.Data type: Array of Objects\n\n```\n\"failed\": [\n  {\n    \"message\": \"String\",\n    \"messageType: \"String\",\n    \"taskId\": \"String\"\n  }\n]\n```\n\n</td></tr><tr><td>\n\nfailed.message\n\n</td><td>\n\nMessage that describes why the task failed to be associated with the template.Data type: String\n\n</td></tr><tr><td>\n\nfailed.messageType\n\n</td><td>\n\nReason for the failure.Data type: String\n\n</td></tr><tr><td>\n\nfailed.taskId\n\n</td><td>\n\nSys\\_id of a task that failed to be associated with the template.Data type: String\n\n</td></tr><tr><td>\n\nskipped\n\n</td><td>\n\nList of tasks that didn't fail, but weren't associated with the template \\(skipped\\).Data type: Array of Objects\n\n```\n\"skipped\": [\n  {\n    \"message\": \"String\",\n    \"messageType: \"String\",\n    \"taskId\": \"String\"\n  }\n]\n```\n\n</td></tr><tr><td>\n\nskipped.message\n\n</td><td>\n\nMessage that describes why the task was skipped.Data type: String\n\n</td></tr><tr><td>\n\nskipped.messageType\n\n</td><td>\n\nReason for the task being skipped.Data type: String\n\n</td></tr><tr><td>\n\nskipped.taskId\n\n</td><td>\n\nSys\\_id of a task that the method skipped associated with the template.Data type: String\n\n</td></tr><tr><td>\n\nsuccess\n\n</td><td>\n\nList of tasks that were successfully associated with the template.Data type: Array of Objects\n\n```\n\"success\": [\n  {\n    \"message\": \"String\",\n    \"messageType: \"String\",\n    \"taskId\": \"String\"\n  }\n]\n```\n\n</td></tr><tr><td>\n\nsuccess.message\n\n</td><td>\n\nNot currently in use.Data type: String\n\n</td></tr><tr><td>\n\nsuccess.messageType\n\n</td><td>\n\nNot currently in use.Data type: String\n\n</td></tr><tr><td>\n\nsuccess.taskId\n\n</td><td>\n\nSys\\_id of a task that was associated with the template.Data type: String\n\n</td></tr><tr><td>\n\nsummary\n\n</td><td>\n\nBrief description of any overall processing errors that occurred, such as if the specified template doesn't exist.Data type: String\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method to add de-duplication tasks to a de-duplication template.\n\n```\n// Add tasks to template\nvar taskIds = [];\ntaskIds.push(\"96d2d25113152200eef2dd828144b0a4\");\ntaskIds.push(\"f785a2c3d7012201de92a5f75e610398\");\ntaskIds.push(\"635dd3dbc128ce0100655f1ec66ed41d\");\n\nvar result = new CMDBDuplicateTemplateUtils().addTasksToTemplate(\"6b43105c37301000deeabfc8bcbe5db2\", taskIds);\n); \ngs.info('Success: ' + result.success);\ngs.info('Failed: ' + result.failed);\ngs.info('Skipped: ' + result.skipped);\ngs.info(Summary: ' + result.summary);\n\n```\n\nOutput:\n\n```\nSuccess: [\n    {\n      \"taskId\": \"f785a2c3d7012201de92a5f75e610398\",\n      \"message\": \"\",\n      \"messageType\": \"\"\n    }\n  ]\nFailed: [\n    {\n      \"taskId\": \"96d2d25113152200eef2dd828144b0a4\",\n      \"message\": \"Failed to add task 96d2d25113152200eef2dd828144b0a4 to template 6b43105c37301000deeabfc8bcbe5db2 because there were update errors.\",\n      \"messageType\": \"update_failed\"\n    }\n  ]\nSkipped: [\n    {\n      \"taskId\": \"635dd3dbc128ce0100655f1ec66ed41d\",\n      \"message\": \"Cannot add de-duplication task(s) to template 6b43105c37301000deeabfc8bcbe5db2 because the template is not published. Publish the template before adding tasks.\",\n      \"messageType\": \"unpublished_template\"\n    }\n  ]\nSummary:\n\n```\n\n## CMDBDuplicateTemplateUtils - removeTemplateFromTask\\(Array taskIds\\)\n\nClears the de-duplication template value in the specified de-duplication task records. By clearing this value, the association between a template and the task is removed.\n\nThe following list describes scenarios where the template value isn’t removed from the task record and is marked as either skipped or failed:\n\n-   The de-duplication template associated with the task is running. The task is marked as skipped.\n-   The task state is \"work in progress\" or the task isn’t found. The task is marked as skipped.\n-   The GlideRecord update for the template column on the task fails. The task is marked as failed.\n\n|Name|Type|Description|\n|----|----|-----------|\n|taskIds|Array|List of sys\\_ids of the de-duplication task records from which to clear the de-duplication template value.|\n\n<table id=\"table_qn5_g3v_xxb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nResult object containing the count of tasks for which the template value removal was successful, skipped, or failed.\n\n```\n{\n  \"failed\": Number,\n  \"success\": Number,\n  \"skipped\": Number\n}\n```\n\n</td></tr><tr><td>\n\nfailed\n\n</td><td>\n\nNumber of tasks that failed to remove the de-duplication template value.Data type: Number\n\n</td></tr><tr><td>\n\nsuccess\n\n</td><td>\n\nNumber of tasks that successfully removed the de-duplication template value.Data type: Number\n\n</td></tr><tr><td>\n\nskipped\n\n</td><td>\n\nNumber of tasks that the method skipped removing the de-duplication template value.Data type: Number\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method to remove de-duplication template values from de-duplication task records.\n\n```\n// Remove tasks from template\nvar taskIds = [];\ntaskIds.push(\"96d2d25113152200eef2dd828144b0a4\");\ntaskIds.push(\"f785a2c3d7012201de92a5f75e610398\");\ntaskIds.push(\"635dd3dbc128ce0100655f1ec66ed41d\");\n\nvar result = new CMDBDuplicateTemplateUtils().removeTemplateFromTasks(taskIds);\n); \ngs.info('Success: ' + result.success);\ngs.info('Failed: ' + result.failed);\ngs.info('Skipped: ' + result.skipped);\n```\n\nOutput:\n\n```\nSuccess: 2\nFailed: 0\nSkipped: 1\n```\n\n"}}