{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":752,"path":"api-reference/server-api-reference/DuplicateTemplateScopedAPI.md","title":"DuplicateTemplate - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# DuplicateTemplate- Scoped\n\nThe DuplicateTemplate API provides methods for users to interact with de-duplication templates by enforcing a set of validations for each method.\n\nDe-duplication task remediation can be more time consuming than desirable when handled individually. Duplication templates enable grouping a set of duplicate tasks and running them together. Use the DuplicateTemplate API to create and consume de-duplication templates. This API runs in the `sn_cmdb` namespace and requires the cmdb\\_dedup\\_admin role to access.\n\nWhen an instance detects duplicate configuration items \\(CIs\\) during identification and reconciliation, it groups each set of duplicate CIs into a de-duplication task for review and remediation. De-duplication tasks provide details about the duplication, including a list of all duplicate CIs. For information, see [Duplicate CIs remediation](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/de-duplication-tasks.md).\n\nSee also: [IdentificationEngine - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/IdentificationEngineScopedAPI.md)\n\n-   **Template life cycle**\n    1.  Use the [CreateTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md) method to create a template in the draft state.\n\n        You can use the following methods to retrieve or update the template:\n\n        -   [getTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n        -   [canAddTasksToTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n        -   [updateTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n    2.  Use the [publishTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md) method to move the template from draft to published state.\n\n        **Note:** Use the [unPublishTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md) method to return a published template to draft state and update the template.\n\n    3.  Optional. Use the [CMDBDuplicateTemplateUtil](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CMDBDuplicateTemplateUtilAPI.md) script include to add or remove tasks.\n    4.  Use the [runTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md) method to run the template.\n\n        To cancel a running task, use the [requestCancellation\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md) method.\n\n    5.  If the template is no longer needed, you can retire the template using the [retireTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md) method.\n-   **Remediating a single task using a template**\n\n    To remediate a single task without running the template, you can preview and remediate de-duplication tasks.\n\n    1.  Use the [previewTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md) method to preview the remediation of a single-task with a template.\n    2.  Use the [remediateTask\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md) method to remediate the de-duplication task with a template.\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## DuplicateTemplate - canAddTasksToTemplate\\(Array taskIds, String templatId\\)\n\nChecks if the provided list of tasks can be added to a template.\n\nUse this method to determine whether tasks are suitable for adding to the template. For example, the specified template might be created for Application Server Tomcat, but the specified de-duplication tasks are created for Linux Server. These tasks don’t have a matching template class, so they can’t be added to the template.\n\n|Name|Type|Description|\n|----|----|-----------|\n|taskIds|Array|Array of sys\\_ids of the de-duplication tasks to add to the template.|\n|templateId|String|Sys\\_id of the template listed in the Reconcile Duplicate Template \\[reconcile\\_duplicate\\_template\\] table.|\n\n<table id=\"table_sl4_t5c_txb\" 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 what tasks can be added, skipped, or failed.```\n{\n  \"success\": [\n    \"<task_id_1>\",\n    \"<task_id_2>\",\n    \"<task_id_3>\"\n  ],\n  \"failed\": [\n    \"<task_id_4>\"\n  ],\n  \"skipped\": [\n    \"<task_id_5>\"\n  ]\n}\n```\n\n</td></tr><tr><td>\n\nfailed\n\n</td><td>\n\nError occurred while checking if the task is compatible with the template. See also [Detecting duplicate CIs](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/id-detect-dup-ci.md).\n\n</td></tr><tr><td>\n\nskipped\n\n</td><td>\n\nThe tasks are incompatible because they don’t have a matching template class, so the task was skipped.\n\n</td></tr><tr><td>\n\nsuccess\n\n</td><td>\n\nThe task matches the template class and can be added to the template.\n\n</td></tr></tbody>\n</table>The following example shows how to check for tasks that can be added to the template.\n\n```\nvar taskIds = [];\ntaskIds.push(<task_id_1>);\ntaskIds.push(<task_id_2>);\ntaskIds.push(<task_id_3>);\n\nvar result = sn_cmdb.DuplicateTemplate.canAddTasksToTemplate(taskIds, <template_id>);\n\ngs.info('Success:' + result.success);\ngs.info('Failed:' + result.failed);\ngs.info('Skipped:' + result.skipped);\n```\n\nOutput:\n\n```\nSuccess: <task_id_1>\nFailed: <task_id_2>\nSkipped: <task_id_3>\n```\n\n## DuplicateTemplate - createTemplate\\(Object template\\)\n\nCreates a de-duplication template in draft state.\n\n<table id=\"table_rl4_t5c_txb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ntemplate\n\n</td><td>\n\nObject\n\n</td><td>\n\nThe template object with different options for creating the template. ```\n{\n  \"allow_master_ci_null_update\": Boolean,\n  \"allow_null_attribute_update\": Boolean,\n  \"description\": \"String\",\n  \"duplicate_ci_action\": \"String\",\n  \"duplicate_ci_updates\": [Array],\n  \"master_ci_condition\": \"String\",\n  \"master_ci_option\": \"String\",\n  \"merge_related_items\": \"String\",\n  \"merge_related_items_condition\": [Array],\n  \"merge_relations_condition\": \"String\",\n  \"merge_relations\": \"String\",\n  \"most_related_items_merge_attributes\": \"String\",\n  \"most_relations_merge_attributes\": \"String\",\n  \"name\": \"String\",\n  \"newest_updated_merge_attributes\": \"String\",\n  \"oldest_created_merge_attributes\": \"String\",\n  \"table\": \"String\",\n  \"task_conditions\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\ntemplate.allow\\_null\\_​attribute\\_update\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nOptional. Flag that indicates if main CI attributes are updated with null values from duplicate CIs when resolving attribute conflicts for CIs within a de-duplication task.Valid values:\n\n-   true: The main CI attributes are updated with null values from duplicate CIs.\n-   false: The main CI attributes aren’t updated with null values from duplicate CIs.\n\nDefault: False\n\n</td></tr><tr><td>\n\ntemplate.allow\\_master\\_ci\\_​null\\_update\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nOptional. Only includes updates from duplicate CIs if the main CI value is null.Flag that indicates whether to include only updates from duplicate CIs if the main CI value is null.\n\nValid values:\n\n-   true: Only include updates from duplicate CIs if the main CI value is null.\n-   false: Include updates from all duplicate CIs.\n\nDefault: False\n\n</td></tr><tr><td>\n\ntemplate.description\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Description to store more information about the template.\n\n</td></tr><tr><td>\n\ntemplate.duplicate\\_​ci\\_action\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Specifies if the duplicate CI is to be deleted or updated with unique custom values.Possible options:\n\n-   delete\n-   update \\(requires specifying **duplicate\\_ci\\_updates**\\)\n\n</td></tr><tr><td>\n\ntemplate.duplicate\\_​ci\\_updates\n\n</td><td>\n\nArray\n\n</td><td>\n\nOptional, unless the setting for **duplicate\\_ci\\_action** is `update`. Array of objects specifying how the duplicate CI values are updated.```\n[\n  {\n    \"element\": \"String\",\n    \"element_label\": \"String\",\n    \"value\": \"String\",\n    \"display\": \"String\"\n  }\n]\n```\n\n</td></tr><tr><td>\n\ntemplate.duplicate\\_​ci\\_updates.element\n\n</td><td>\n\nString\n\n</td><td>\n\nThe system dictionary name of a reference field.\n\n</td></tr><tr><td>\n\ntemplate.duplicate\\_​ci\\_updates.element\\_label\n\n</td><td>\n\nString\n\n</td><td>\n\nThe label that the reference field displays.\n\n</td></tr><tr><td>\n\ntemplate.duplicate\\_​ci\\_updates.value\n\n</td><td>\n\nString\n\n</td><td>\n\nValue for a reference field, that is, the contents of the reference field.\n\n</td></tr><tr><td>\n\ntemplate.duplicate\\_​ci\\_updates.display\n\n</td><td>\n\nString\n\n</td><td>\n\nDisplay value for a reference field.\n\n</td></tr><tr><td>\n\ntemplate.master\\_ci\\_​option\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Specifies how the main CI is selected for a de-duplication task when applying this template. Possible options:\n\n-   conditional \\(must specify **master\\_ci\\_condition**\\)\n-   most\\_related\\_items – Attributes to be merged from the CI with the most related items to the main CI.\n-   most\\_relations – Attributes to be merged from the CI with the most relationships to the main CI.\n-   newest\\_created – separated attributes to be merged from the most recently updated CI to the main CI.\n-   oldest\\_created – Comma-separated attributes to be merged from the oldest-created CI to the main CI.\n\n</td></tr><tr><td>\n\ntemplate.master\\_ci\\_condition\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional \\(required if the value of **master\\_ci\\_option** is `conditional`\\). Encoded query to specify how the main CI is selected. If multiple CIs or no CIs match the query, the method selects the most recently updated CI as the main CI. The encoded query is evaluated for the template table. This table is identified in the **table** property.For details, see [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).\n\n</td></tr><tr><td>\n\ntemplate.merge\\_relations\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Specifies how the relationships for duplicate CIs within a de-duplication task are merged when applying this template. Possible options:\n\n-   all\n-   conditional\n-   none\n\n</td></tr><tr><td>\n\ntemplate.merge\\_relations\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Specifies how the relationships for duplicate CIs within a de-duplication task are merged when applying this template. Possible options:\n\n-   all\n-   conditional\n-   none\n\n</td></tr><tr><td>\n\ntemplate.merge\\_relations\\_​condition\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional \\(required if the value of **merge\\_relations** is `conditional`\\). Encoded query to specify if all or none of the relationships from duplicate CIs are merged. The query is evaluated on the main CI that is selected for the de-duplication task. If the query returns true, all relationships are merged. If false, no relationships are merged.The encoded query is evaluated for the template table. This table is identified in the **table** property.\n\nFor details, see [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).\n\n</td></tr><tr><td>\n\ntemplate.merge\\_related\\_items\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Specifies which related tables for duplicate CIs within a de-duplication task are merged to the main CI when applying this template. See also [Remediate a de-duplication task \\(manual\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/reconcile-dup-task.md).Possible options:\n\n-   all\\_available – Includes the default-related tables and any related tables that reference duplicate CIs for the de-duplication task remediated via the template.\n-   conditional\n-   default – Includes related entries provided by the Duplicate CI Remediator Default Related Items module.\n-   none\n\n</td></tr><tr><td>\n\ntemplate.merge\\_related\\_items\\_​condition\n\n</td><td>\n\nArray\n\n</td><td>\n\nOptional. List of related entries with an encoded query for each related entry. Each query is evaluated on the main CI that is selected for the task. If the query returns true, the related entries are merged during the remediation of a de-duplication task. If false, related entries aren’t merged.```\n\"merge_related_items_condition\": [\n  {\n    \"related_entry\": \"String\",\n    \"condition\": \"String\"\n  }\n]\n```\n\nFor details, see [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).\n\n</td></tr><tr><td>\n\ntemplate.most\\_relations\\_​merge\\_attributes\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Comma-separated attributes to be merged from the CI with the most relationships to the main CI.\n\n</td></tr><tr><td>\n\ntemplate.most\\_related\\_items\\_​merge\\_attributes\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Comma-separated attributes to be merged from the CI with the most related items to the main CI.\n\n</td></tr><tr><td>\n\ntemplate.name\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the template.\n\n</td></tr><tr><td>\n\ntemplate.newest\\_updated\\_​merge\\_attributes\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Comma-separated attributes to be merged from the most recently updated CI to the main CI.\n\n</td></tr><tr><td>\n\ntemplate.oldest\\_created\\_​merge\\_attributes\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Comma-separated attributes to be merged from the oldest-created CI to the main CI.\n\n</td></tr><tr><td>\n\ntemplate.table\n\n</td><td>\n\nString\n\n</td><td>\n\nTable for which the template is created.\n\n</td></tr><tr><td>\n\ntemplate.task\\_conditions\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Encoded query to be evaluated when the template runs. This query is evaluated on the Reconcile Duplicate Task Data \\[reconcile\\_duplicate\\_task\\_data\\] table. All tasks returned from this query are considered during the template evaluation. **Note:** Even if a task is returned as a part of the query, it doesn’t guarantee that the template run processes the task. Other factors might cause the task to be skipped during template processing.\n\nFor details, see [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Sys\\_id of the template created in the Reconcile Duplicate Templates \\[reconcile\\_duplicate\\_template\\] table.|\n\nThe following example shows how to create a de-duplication template.\n\n```\nvar template = {\n  \"name\": \"Test Windows Template\",\n  \"table\": \"cmdb_ci_win_server\",\n  \"description\": \"This is a Windows server template\",\n  \"master_ci_option\": \"oldest_created\",\n  \"master_ci_condition\": \"\",\n  \"allow_null_attribute_update\": false,\n  \"allow_master_ci_null_update\": false,\n  \"oldest_created_merge_attributes\": \"serial_number,os_version\",\n  \"merge_relations\": \"all\",\n  \"merge_relations_condition\": \"\",\n  \"merge_related_items\": \"conditional\",\n  \"merge_related_items_condition\": [\n    {\n      \"related_entry\": \"change_request.cmdb_ci\",\n      \"condition\": \"ramCONTAINS1024\"\n    },\n    {\n      \"related_entry\": \"incident.cmdb_ci\",\n      \"condition\": \"os_versionCONTAINSWindows\"\n    }\n  ],\n  \"duplicate_ci_action\": \"delete\",\n  \"duplicate_ci_updates\":   [{\n    \"element\": \"ram\",\n    \"element_label\": \"RAM (MB)\",\n    \"value\": \"1024\",\n    \"display\": \"1024\"\n  }],\n  \"task_conditions\": \"category=attribute^key=serial_number^value=E2BX1^EQ\"\n};\n\nvar templateId = sn_cmdb.DuplicateTemplate.createTemplate(template);\n\ngs.info(templateId);\n```\n\nOutput:\n\n```\n8dfcd36e042b2510f877c1665753a485\n```\n\n## DuplicateTemplate - getTemplate\\(String templateId\\)\n\nGets the template object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|templateId|String|Sys\\_id of the template listed in the Reconcile Duplicate Template \\[reconcile\\_duplicate\\_template\\] table.|\n\n<table id=\"table_sl4_t5c_txb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr id=\"row_DupTemp-templateObj\"><td>\n\nObject\n\n</td><td>\n\nThe template object with different options for creating the template.```\n{\n  \"allow_master_ci_null_update\": Boolean,\n  \"allow_null_attribute_update\": Boolean,\n  \"description\": \"String\",\n  \"duplicate_ci_action\": \"String\",\n  \"duplicate_ci_updates\": [Array],\n  \"master_ci_condition\": \"String\",\n  \"master_ci_option\": \"String\",\n  \"merge_related_items\": \"String\",\n  \"merge_related_items_condition\": [Array],\n  \"merge_relations_condition\": \"String\",\n  \"merge_relations\": \"String\",\n  \"most_related_items_merge_attributes\": \"String\",\n  \"most_relations_merge_attributes\": \"String\",\n  \"name\": \"String\",\n  \"newest_updated_merge_attributes\": \"String\",\n  \"oldest_created_merge_attributes\": \"String\",\n  \"table\": \"String\",\n  \"task_conditions\": \"String\"\n}\n```\n\n</td></tr><tr id=\"row_DupTemp-template-allow-null-attr\"><td>\n\n&lt;Object&gt;.allow\\_null\\_ attribute\\_update\n\n</td><td>\n\nFlag that indicates if main CI attributes are updated with null values from duplicate CIs when resolving attribute conflicts for CIs within a de-duplication task.Valid values:\n\n-   true: The main CI attributes are updated with null values from duplicate CIs.\n-   false: The main CI attributes aren’t updated with null values from duplicate CIs.\n\nData type: Boolean\n\n</td></tr><tr id=\"row_DupTemp-template-master-ci-nul\"><td>\n\n&lt;Object&gt;.allow\\_master\\_ci\\_ null\\_update\n\n</td><td>\n\nOnly includes updates from duplicate CIs if the main CI value is null.Valid values:\n\n-   true: Only include updates from duplicate CIs if the main CI value is null.\n-   false: Include updates from all duplicate CIs.\n\nData type: Boolean\n\n</td></tr><tr id=\"row_DupTemp-template-desc\"><td>\n\n&lt;Object&gt;.description\n\n</td><td>\n\nDescription to store more information about the template.Data type: String\n\n</td></tr><tr id=\"row_DupTemp-template-dup-ci-action\"><td>\n\n&lt;Object&gt;.duplicate\\_ ci\\_action\n\n</td><td>\n\nSpecifies if the duplicate CI is to be deleted or updated with unique custom values.Possible options:\n\n-   delete\n-   update \\(requires specifying **duplicate\\_ci\\_updates**\\)\n\nData type: String\n\n</td></tr><tr id=\"row_DupTemp-template-dup-ci-updts\"><td>\n\n&lt;Object&gt;.duplicate\\_ ci\\_updates\n\n</td><td>\n\nArray of objects specifying how the duplicate CI values are updated.```\n[\n  {\n    \"element\": \"String\",\n    \"element_label\": \"String\",\n    \"value\": \"String\",\n    \"display\": \"String\"\n  }\n]\n```\n\nData type: Object\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.duplicateCIUpdates.element\n\n</td><td>\n\nThe system dictionary name of a reference field.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.duplicateCIUpdates.element\\_label\n\n</td><td>\n\nThe label that the reference field displays.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.duplicateCIUpdates.value\n\n</td><td>\n\nValue for a reference field, that is, the contents of the reference field.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.duplicateCIUpdates.display\n\n</td><td>\n\nDisplay value for a reference field.Data type: String\n\n</td></tr><tr id=\"row_DupTemp-template-master-ci-opt\"><td>\n\n&lt;Object&gt;.master\\_ci\\_ option\n\n</td><td>\n\nSpecifies how the main CI is selected for a de-duplication task when applying this template.Possible options:\n\n-   conditional \\(must specify **master\\_ci\\_condition**\\)\n-   most\\_related\\_items – Attributes to be merged from the CI with the most related items to the main CI.\n-   most\\_relations – Attributes to be merged from the CI with the most relationships to the main CI.\n-   newest\\_created – separated attributes to be merged from the most recently updated CI to the main CI.\n-   oldest\\_created – Comma-separated attributes to be merged from the oldest-created CI to the main CI.\n\nData type: String\n\n</td></tr><tr id=\"row_DupTemp-template-mrg-relations\"><td>\n\n&lt;Object&gt;.merge\\_relations\n\n</td><td>\n\nSpecifies how the relationships for duplicate CIs within a de-duplication task are merged when applying this template.Possible options:\n\n-   all\n-   conditional\n-   none\n\nData type: String\n\n</td></tr><tr id=\"row_DupTemp-template-mrgRel-itms\"><td>\n\n&lt;Object&gt;.merge\\_related\\_items\n\n</td><td>\n\nSpecifies which related tables for duplicate CIs within a de-duplication task are merged to the main CI when applying this template. See also [Remediate a de-duplication task \\(manual\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/reconcile-dup-task.md).Possible options:\n\n-   all\\_available – Includes the default-related tables and any related tables that reference duplicate CIs for the de-duplication task remediated via the template.\n-   conditional\n-   default – Includes related entries provided by the Duplicate CI Remediator Default Related Items module.\n-   none\n\nData type: String\n\n</td></tr><tr id=\"row_DupTemp-template-mrgRel-itmCnd\"><td>\n\n&lt;Object&gt;.merge\\_related\\_items\\_ condition\n\n</td><td>\n\nList of related entries with an encoded query for each related entry. Each query is evaluated on the main CI that is selected for the task. If the query returns true, the related entries are merged during the remediation of a de-duplication task. If false, related entries aren’t merged.For details, see [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).\n\nData type: Array\n\n</td></tr><tr id=\"row_DupTemp-template-most-relationsMA\"><td>\n\n&lt;Object&gt;.most\\_relations\\_ merge\\_attributes\n\n</td><td>\n\nComma-separated attributes to be merged from the CI with the most relationships to the main CI.Data type: String\n\n</td></tr><tr id=\"row_DupTemp-template-mostRel-itmMA\"><td>\n\n&lt;Object&gt;.most\\_related\\_items\\_ merge\\_attributes\n\n</td><td>\n\nComma-separated attributes to be merged from the CI with the most related items to the main CI.Data type: String\n\n</td></tr><tr id=\"row_DupTemp-template-name\"><td>\n\n&lt;Object&gt;.name\n\n</td><td>\n\nName of the template.Data type: String\n\n</td></tr><tr id=\"row_DupTemp-template-newst-updtdMA\"><td>\n\n&lt;Object&gt;.newest\\_updated\\_ merge\\_attributes\n\n</td><td>\n\nComma-separated attributes to be merged from the most recently updated CI to the main CI.Data type: String\n\n</td></tr><tr id=\"row_DupTemp-template-oldst-crtdMA\"><td>\n\n&lt;Object&gt;.oldest\\_created\\_ merge\\_attributes\n\n</td><td>\n\nComma-separated attributes to be merged from the oldest-created CI to the main CI.Data type: String\n\n</td></tr><tr id=\"row_DupTemp-template-table\"><td>\n\n&lt;Object&gt;.table\n\n</td><td>\n\nTable for which the template is created.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.task\\_condition\\_table\n\n</td><td>\n\nLocation of the table task conditions, that is, the Reconcile Duplicate Task Data \\[reconcile\\_duplicate\\_task\\_data\\] table. The value never changes and the table is intended for internal use only.Data type: String\n\n</td></tr><tr id=\"row_DupTemp-template-task-cond\"><td>\n\n&lt;Object&gt;.task\\_conditions\n\n</td><td>\n\nEncoded query to be evaluated when the template runs. This query is evaluated on the Reconcile Duplicate Task Data \\[reconcile\\_duplicate\\_task\\_data\\] table. All tasks returned from this query are considered during the template evaluation. **Note:** Even if a task is returned as a part of the query, it doesn’t guarantee that the template run processes the task. Other factors might cause the task to be skipped during template processing.\n\nFor details, see [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).\n\nData type: String\n\n</td></tr></tbody>\n</table>The following example shows how to retrieve a template.\n\n```\nvar template = sn_cmdb.DuplicateTemplate.getTemplate('<template_id>');\ngs.info(JSON.stringify(template));\n```\n\nOutput:\n\n```\n{\n  \"most_relations_merge_attributes\": \"\",\n  \"task_conditions\": \"category=attribute^key=serial_number^value=E2BX1^EQ\",\n  \"duplicate_ci_updates\": \"org.mozilla.javascript.NativeArray@5d3b19ef\",\n  \"description\": \"This is a Windows server template\",\n  \"master_ci_option\": \"oldest_created\",\n  \"merge_related_items\": \"conditional\",\n  \"duplicate_ci_action\": \"delete\",\n  \"newest_updated_merge_attributes\": \"\",\n  \"merge_related_items_condition\": [\n    {\n      \"condition\": \"os_versionCONTAINSWindows\",\n      \"related_entry\": \"incident.cmdb_ci\"\n    },\n    {\n      \"condition\": \"ramCONTAINS1024\",\n      \"related_entry\": \"change_request.cmdb_ci\"\n    }\n  ],\n  \"most_related_items_merge_attributes\": \"\",\n  \"merge_relations\": \"all\",\n  \"task_condition_table\": \"reconcile_duplicate_task_data\",\n  \"name\": \"Test Windows Template\",\n  \"allow_null_attribute_update\": false,\n  \"table\": \"cmdb_ci_win_server\",\n  \"allow_master_ci_null_update\": false,\n  \"oldest_created_merge_attributes\": \"serial_number,os_version\"\n}\n```\n\n## DuplicateTemplate - previewTemplate\\(String templateId, String taskId\\)\n\nGenerates a preview of how different template options were applied to the de-duplication task and how it’s to be remediated.\n\nThis method validates all the required attributes before generating the preview for the task using the template. Templates can be created or updated without specifying the required attributes. The required attributes must be provided to preview any de-duplication task.\n\nThe following attributes are required:\n\n-   duplicate\\_ci\\_action\n-   master\\_ci\\_option\n-   merge\\_related\\_items\n-   merge\\_relations\n-   name\n-   table\n\n**Note:** Although this method validates all of the attributes, there’s no requirement for the template to be in the published state for a preview.\n\nUse the [remediateTask\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md) method to remediate de-duplication tasks.\n\n|Name|Type|Description|\n|----|----|-----------|\n|templateId|String|Sys\\_id of the template listed in the Reconcile Duplicate Template \\[reconcile\\_duplicate\\_template\\] table.|\n|taskId|String|Sys\\_id of the de-duplication task listed in the Remediate Duplicate Task \\[reconcile\\_duplicate\\_task\\] table.|\n\n<table id=\"table_sl4_t5c_txb\" 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\nPreview object with values showing how the de-duplication tasks can be remediated using the template.```\n{\n  \"allClassCIMap\": {Object},\n  \"duplicateCIAction\": \"String\",\n  \"duplicateCIUpdates\": [Array],\n  \"masterCI\": \"String\",\n  \"mergeRelations\": Boolean,\n  \"relatedTablesMerged\": [Array],  \n  \"resolvedFieldCIMap\": [Array],\n  \"taskId\": \"String\",\n  \"tooManyDuplicates\": Boolean\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.allClassCIMap\n\n</td><td>\n\nList of sys\\_ids of the CIs within a de-duplication task, grouped by CI class. For example, **cmdb\\_ci\\_computer**.```\n\"allClassCIMap\": {\n  \"<ci_class_name>\": [\n    \"<ci_sys_id_1>\",\n    \"<ci_sys_id_2>\"\n  ]\n}\n```\n\nData type: Object\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.duplicateCIAction\n\n</td><td>\n\nSpecifies if the duplicate CI is to be deleted or updated with unique custom values.Possible options:\n\n-   delete\n-   update \\(requires specifying **duplicate\\_ci\\_updates**\\)\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.duplicateCIUpdates\n\n</td><td>\n\nArray of objects specifying how the duplicate CI values are updated.```\n[\n  {\n    \"element\": \"String\",\n    \"element_label\": \"String\",\n    \"value\": \"String\",\n    \"display\": \"String\"\n  }\n]\n```\n\nData type: Array\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.duplicateCIUpdates.element\n\n</td><td>\n\nThe system dictionary name of a reference field.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.duplicateCIUpdates.element\\_label\n\n</td><td>\n\nThe label that the reference field displays.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.duplicateCIUpdates.value\n\n</td><td>\n\nValue for a reference field, that is, the contents of the reference field.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.duplicateCIUpdates.display\n\n</td><td>\n\nDisplay value for a reference field.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.masterCI\n\n</td><td>\n\nSys\\_id of the CI that was selected as the main CI.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.mergeRelations\n\n</td><td>\n\nSpecifies how the relationships for duplicate CIs within a de-duplication task are merged when applying this template.Possible options:\n\n-   all\n-   conditional\n-   none\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.relatedTablesMerged\n\n</td><td>\n\nSpecifies which related tables for duplicate CIs within a de-duplication task are merged to the main CI when applying this template. See also [Remediate a de-duplication task \\(manual\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/reconcile-dup-task.md).Possible options:\n\n-   all\\_available – Includes the default-related tables and any related tables that reference duplicate CIs for the de-duplication task remediated via the template.\n-   conditional\n-   default – Includes related entries provided by the Duplicate CI Remediator Default Related Items module.\n-   none\n\nData type: Array\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.resolvedFieldCIMap\n\n</td><td>\n\nArray of elements to be merged from duplicate CIs to the main CI.```\n\"resolvedFieldCIMap\": [\n  {\n    \"element\": \"String\",\n    \"sys_id\": \"String\"\n  }\n]\n```\n\nData type: Array\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.resolvedFieldCIMap.​element\n\n</td><td>\n\nName of the element to be merged from a duplicate CI to the main CI.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.resolvedFieldCIMap.​sys\\_id\n\n</td><td>\n\nSys\\_id of the element to be merged from a duplicate CI to the main CI.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.taskId\n\n</td><td>\n\nSys\\_id of the de-duplication task listed in the Remediate Duplicate Task \\[reconcile\\_duplicate\\_task\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.tooManyDuplicates\n\n</td><td>\n\nFlag that indicates whether the task has more than the maximum number of CIs. The threshold is determined by comparing the value of the system property glide.duplicate\\_ci\\_ remediator.max.cis \\(default value 1000 CIs\\).Valid values:\n\n-   true: Task number of CIs exceeds the maximum number of CIs.\n-   false: Task number of CIs don't exceed the maximum number of CIs.\n\nData type: Boolean\n\n</td></tr></tbody>\n</table>The following example shows how to get a preview of de-duplication remediation for a specified template.\n\n```\nvar preview = sn_cmdb.DuplicateTemplate.previewTemplate(\"<template_id>\", \"<task_id>\");\ngs.info(JSON.stringify(preview));\n```\n\nOutput:\n\n```\n{\n  \"taskId\": \"<task_id>\",\n  \"masterCI\": \"<ci_sys_id_1>\",\n  \"allClassCIMap\": {\n    \"cmdb_ci_computer\": [\n      \"<ci_sys_id_1>\",\n      \"<ci_sys_id_2>\"\n    ]\n  },\n  \"resolvedFieldCIMap\": [\n    {\n      \"element\": \"ram\",\n      \"sys_id\": \"<ci_sys_id_2>\"\n    },\n    {\n      \"element\": \"os_version\",\n      \"sys_id\": \"<ci_sys_id_2>\"\n    }\n  ],\n  \"mergeRelations\": true,\n  \"relatedTablesMerged\": [\n    \"incident.cmdb_ci\",\n    \"change_request.cmdb_ci\"\n  ],\n  \"duplicateCIAction\": \"delete\",\n  \"duplicateCIUpdates\": [],\n  \"tooManyDuplicates\": false\n}\n```\n\n## DuplicateTemplate - publishTemplate\\(String templateId\\)\n\nPublishes a template. When successful, the template moves from draft to published state.\n\nThis method validates all the required attributes before publishing the template. You can create or update templates without specifying the required attributes, but the attributes must be provided before publishing a template.\n\nThe following attributes are required:\n\n-   duplicate\\_ci\\_action\n-   master\\_ci\\_option\n-   merge\\_related\\_items\n-   merge\\_relations\n-   name\n-   table\n\nIn published state, you can run the template using the [runTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md) method.\n\nSee also:\n\n-   [previewTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n-   [unPublishTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n-   [updateTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|templateId|String|Sys\\_id of the template listed in the Reconcile Duplicate Template \\[reconcile\\_duplicate\\_template\\] table.|\n\n<table id=\"table_sl4_t5c_txb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the template was published.\n\n Valid values:\n\n-   true: The template was published.\n-   false: The template wasn’t published.\n\n</td></tr></tbody>\n</table>The following example shows how to publish a template and display results.\n\n```\nvar isPublished = sn_cmdb.DuplicateTemplate.publishTemplate('<template_id>');\ngs.info(isPublished);\n```\n\nOutput:\n\n```\ntrue\n```\n\n## DuplicateTemplate - remediateTask\\(String templateId, String taskId\\)\n\nRemediates a de-duplication task using the template.\n\nIf the template isn’t in the published state, the template can't be run and the method throws an exception.\n\nUse the [previewTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md) method to preview how de-duplication tasks are to be remediated.\n\nSee also.\n\n-   [Duplicate CIs remediation](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/de-duplication-tasks.md)\n-   [publishTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n-   [Remediate a de-duplication task \\(manual\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/reconcile-dup-task.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|templateId|String|Sys\\_id of the template listed in the Reconcile Duplicate Template \\[reconcile\\_duplicate\\_template\\] table.|\n|taskId|String|Sys\\_id of the de-duplication task listed in the Remediate Duplicate Task \\[reconcile\\_duplicate\\_task\\] table.|\n\n|Type|Description|\n|----|-----------|\n|String|If successful, the merge resolution ID for the de-duplication task remediation. This merge resolution ID the sys\\_id of a record in the Duplicate CI Remediation \\[cmdb\\_duplicate\\_ci\\_remediation\\] table. If unsuccessful, the template might not be in the published state.|\n\nThe following example shows how to remediate a de-duplication task.\n\n```\nvar mergeResolutionId = sn_cmdb.DuplicateTemplate.remediateTask(\"<template_id>\", \"<task_id>\");\ngs.info(mergeResolutionId);\n```\n\nOutput:\n\n```\n<merge_resolution_id>\n```\n\n## DuplicateTemplate - requestCancellation\\(String templateRunId\\)\n\nCancels an existing template run.\n\nA cancel request can only be made for a template run if it's in draft, ready, or running state.\n\nAfter a template run cancel request, the template run state changes to the intermediate stage Cancel Requested.\n\nRunning this method doesn’t automatically cancel template runs in Ready or Draft state. The template run state doesn’t change to Cancelled until any tasks running are complete. At that point any remaining tasks staged for remediation change from cancel requested to canceled.\n\nSee also:\n\n-   [publishTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n-   [runTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n-   [retireTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|templateRunId|String|Sys\\_id of the template run listed in the De-Duplication Template Run \\[reconcile\\_duplicate\\_template\\_run\\] table.|\n\n<table id=\"table_sl4_t5c_txb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nFlag that indicates whether the cancel request was successful.\n\n Valid values:\n\n-   true: The cancel request was successful.\n-   false: The cancel request wasn’t successful.\n\n</td></tr></tbody>\n</table>The following example shows how to cancel a template run and display whether the operation is successful.\n\n```\nvar isCancelled = sn_cmdb.DuplicateTemplate.requestCancellation(\"487c67e2046b2510f877c1665753a4cc\");\ngs.info(isCancelled);\n```\n\nOutput:\n\n```\ntrue\n```\n\n## DuplicateTemplate - retireTemplate\\(String templateId\\)\n\nRetires a template.\n\nUse this method to move a template to the retire state if it’s no longer needed.\n\nThe template can't be retired and the method throws an exception under the following conditions:\n\n-   The template is in the published state.\n-   The template is running or scheduled to run.\n\nSee also:\n\n-   [publishTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n-   [runTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n-   [requestCancellation\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n-   [DuplicateTemplate - unPublishTemplate\\(String templateId\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|templateId|String|Sys\\_id of the template listed in the Reconcile Duplicate Template \\[reconcile\\_duplicate\\_template\\] table.|\n\n<table id=\"table_sl4_t5c_txb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the template is retired.Valid values:\n\n-   true: The template is retired.\n-   false: The template couldn’t be retired because it was running, scheduled to be run, or in published state\n\n</td></tr></tbody>\n</table>The following example shows how to retire a template and display results.\n\n```\nvar isRetired = sn_cmdb.DuplicateTemplate.retireTemplate(<template_id>);\ngs.info(isRetired);\n```\n\nOutput:\n\n```\ntrue\n```\n\n## DuplicateTemplate - runTemplate\\(String templateId\\)\n\nSchedules a remediation run for a de-duplication template in the published state. A template can be run multiple times but you can only schedule one run at a time.\n\nIf the template isn’t in published state, it can't be run and the method throws an exception. Use the [publishTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md) method to move the template from draft to published state.\n\nTo cancel a running task, use the [requestCancellation\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md) method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|templateId|String|Sys\\_id of the template listed in the Reconcile Duplicate Template \\[reconcile\\_duplicate\\_template\\] table.|\n\n|Type|Description|\n|----|-----------|\n|String|Sys\\_id of the template that was run listed in the De-Duplication Template Run \\[reconcile\\_duplicate\\_template\\_run\\] table. If unsuccessful, the template might not be in published state.|\n\nThe following example shows how to schedule a run for a published de-duplication template.\n\n```\nvar template = sn_cmdb.DuplicateTemplate.runTemplate('<template_id>');\ngs.info(JSON.stringify(template));\n```\n\nOutput:\n\n```\n487c67e2046b2510f877c1665753a4cc\n```\n\n## DuplicateTemplate - unPublishTemplate\\(String templateId\\)\n\nUnpublishes a template.\n\nThis method moves the template from the published state to the draft state, which enables updating the template. The template can't be unpublished if it is running or scheduled to be run.\n\nSee also:\n\n-   [publishTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n-   [requestCancellation\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n-   [updateTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|templateId|String|Sys\\_id of the template listed in the Reconcile Duplicate Template \\[reconcile\\_duplicate\\_template\\] table.|\n\n<table id=\"table_sl4_t5c_txb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the template was successfully unpublished.\n\n Valid values:\n\n-   true: The template was successfully unpublished.\n-   false: The template wasn’t successfully unpublished. The template might be running or scheduled to be run.\n\n</td></tr></tbody>\n</table>The following example shows how to unpublish a template and display results.\n\n```\nvar isUnPublished = sn_cmdb.DuplicateTemplate.unPublishTemplate(<template_id>);\ngs.info(isUnPublished);\n```\n\nOutput:\n\n```\ntrue\n```\n\n## DuplicateTemplate - updateTemplate\\(String templateId, Object template\\)\n\nUpdates a de-duplication template in draft state.\n\nSee also:\n\n-   [unPublishTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n-   [canAddTasksToTemplate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DuplicateTemplateScopedAPI.md)\n\n<table id=\"table_rl4_t5c_txb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ntemplateId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the template listed in the Reconcile Duplicate Template \\[reconcile\\_duplicate\\_template\\] table.\n\n</td></tr><tr><td>\n\ntemplate\n\n</td><td>\n\nObject\n\n</td><td>\n\nThe template object with different options for creating the template. ```\n{\n  \"allow_master_ci_null_update\": Boolean,\n  \"allow_null_attribute_update\": Boolean,\n  \"description\": \"String\",\n  \"duplicate_ci_action\": \"String\",\n  \"duplicate_ci_updates\": [Array],\n  \"master_ci_condition\": \"String\",\n  \"master_ci_option\": \"String\",\n  \"merge_related_items\": \"String\",\n  \"merge_related_items_condition\": [Array],\n  \"merge_relations_condition\": \"String\",\n  \"merge_relations\": \"String\",\n  \"most_related_items_merge_attributes\": \"String\",\n  \"most_relations_merge_attributes\": \"String\",\n  \"name\": \"String\",\n  \"newest_updated_merge_attributes\": \"String\",\n  \"oldest_created_merge_attributes\": \"String\",\n  \"table\": \"String\",\n  \"task_conditions\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\ntemplate.allow\\_null\\_​attribute\\_update\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nOptional. Flag that indicates if main CI attributes are updated with null values from duplicate CIs when resolving attribute conflicts for CIs within a de-duplication task.Valid values:\n\n-   true: The main CI attributes are updated with null values from duplicate CIs.\n-   false: The main CI attributes aren’t updated with null values from duplicate CIs.\n\nDefault: False\n\n</td></tr><tr><td>\n\ntemplate.allow\\_master\\_ci\\_​null\\_update\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nOptional. Only includes updates from duplicate CIs if the main CI value is null.Flag that indicates whether to include only updates from duplicate CIs if the main CI value is null.\n\nValid values:\n\n-   true: Only include updates from duplicate CIs if the main CI value is null.\n-   false: Include updates from all duplicate CIs.\n\nDefault: False\n\n</td></tr><tr><td>\n\ntemplate.description\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Description to store more information about the template.\n\n</td></tr><tr><td>\n\ntemplate.duplicate\\_​ci\\_action\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Specifies if the duplicate CI is to be deleted or updated with unique custom values.Possible options:\n\n-   delete\n-   update \\(requires specifying **duplicate\\_ci\\_updates**\\)\n\n</td></tr><tr><td>\n\ntemplate.duplicate\\_​ci\\_updates\n\n</td><td>\n\nArray\n\n</td><td>\n\nOptional, unless the setting for **duplicate\\_ci\\_action** is `update`. Array of objects specifying how the duplicate CI values are updated.```\n[\n  {\n    \"element\": \"String\",\n    \"element_label\": \"String\",\n    \"value\": \"String\",\n    \"display\": \"String\"\n  }\n]\n```\n\n</td></tr><tr><td>\n\ntemplate.duplicate\\_​ci\\_updates.element\n\n</td><td>\n\nString\n\n</td><td>\n\nThe system dictionary name of a reference field.\n\n</td></tr><tr><td>\n\ntemplate.duplicate\\_​ci\\_updates.element\\_label\n\n</td><td>\n\nString\n\n</td><td>\n\nThe label that the reference field displays.\n\n</td></tr><tr><td>\n\ntemplate.duplicate\\_​ci\\_updates.value\n\n</td><td>\n\nString\n\n</td><td>\n\nValue for a reference field, that is, the contents of the reference field.\n\n</td></tr><tr><td>\n\ntemplate.duplicate\\_​ci\\_updates.display\n\n</td><td>\n\nString\n\n</td><td>\n\nDisplay value for a reference field.\n\n</td></tr><tr><td>\n\ntemplate.master\\_ci\\_​option\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Specifies how the main CI is selected for a de-duplication task when applying this template. Possible options:\n\n-   conditional \\(must specify **master\\_ci\\_condition**\\)\n-   most\\_related\\_items – Attributes to be merged from the CI with the most related items to the main CI.\n-   most\\_relations – Attributes to be merged from the CI with the most relationships to the main CI.\n-   newest\\_created – separated attributes to be merged from the most recently updated CI to the main CI.\n-   oldest\\_created – Comma-separated attributes to be merged from the oldest-created CI to the main CI.\n\n</td></tr><tr><td>\n\ntemplate.master\\_ci\\_condition\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional \\(required if the value of **master\\_ci\\_option** is `conditional`\\). Encoded query to specify how the main CI is selected. If multiple CIs or no CIs match the query, the method selects the most recently updated CI as the main CI. The encoded query is evaluated for the template table. This table is identified in the **table** property.For details, see [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).\n\n</td></tr><tr><td>\n\ntemplate.merge\\_relations\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Specifies how the relationships for duplicate CIs within a de-duplication task are merged when applying this template. Possible options:\n\n-   all\n-   conditional\n-   none\n\n</td></tr><tr><td>\n\ntemplate.merge\\_relations\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Specifies how the relationships for duplicate CIs within a de-duplication task are merged when applying this template. Possible options:\n\n-   all\n-   conditional\n-   none\n\n</td></tr><tr><td>\n\ntemplate.merge\\_relations\\_​condition\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional \\(required if the value of **merge\\_relations** is `conditional`\\). Encoded query to specify if all or none of the relationships from duplicate CIs are merged. The query is evaluated on the main CI that is selected for the de-duplication task. If the query returns true, all relationships are merged. If false, no relationships are merged.The encoded query is evaluated for the template table. This table is identified in the **table** property.\n\nFor details, see [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).\n\n</td></tr><tr><td>\n\ntemplate.merge\\_related\\_items\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Specifies which related tables for duplicate CIs within a de-duplication task are merged to the main CI when applying this template. See also [Remediate a de-duplication task \\(manual\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/reconcile-dup-task.md).Possible options:\n\n-   all\\_available – Includes the default-related tables and any related tables that reference duplicate CIs for the de-duplication task remediated via the template.\n-   conditional\n-   default – Includes related entries provided by the Duplicate CI Remediator Default Related Items module.\n-   none\n\n</td></tr><tr><td>\n\ntemplate.merge\\_related\\_items\\_​condition\n\n</td><td>\n\nArray\n\n</td><td>\n\nOptional. List of related entries with an encoded query for each related entry. Each query is evaluated on the main CI that is selected for the task. If the query returns true, the related entries are merged during the remediation of a de-duplication task. If false, related entries aren’t merged.```\n\"merge_related_items_condition\": [\n  {\n    \"related_entry\": \"String\",\n    \"condition\": \"String\"\n  }\n]\n```\n\nFor details, see [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).\n\n</td></tr><tr><td>\n\ntemplate.most\\_relations\\_​merge\\_attributes\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Comma-separated attributes to be merged from the CI with the most relationships to the main CI.\n\n</td></tr><tr><td>\n\ntemplate.most\\_related\\_items\\_​merge\\_attributes\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Comma-separated attributes to be merged from the CI with the most related items to the main CI.\n\n</td></tr><tr><td>\n\ntemplate.name\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the template.\n\n</td></tr><tr><td>\n\ntemplate.newest\\_updated\\_​merge\\_attributes\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Comma-separated attributes to be merged from the most recently updated CI to the main CI.\n\n</td></tr><tr><td>\n\ntemplate.oldest\\_created\\_​merge\\_attributes\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Comma-separated attributes to be merged from the oldest-created CI to the main CI.\n\n</td></tr><tr><td>\n\ntemplate.table\n\n</td><td>\n\nString\n\n</td><td>\n\nTable for which the template is created.\n\n</td></tr><tr><td>\n\ntemplate.task\\_conditions\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Encoded query to be evaluated when the template runs. This query is evaluated on the Reconcile Duplicate Task Data \\[reconcile\\_duplicate\\_task\\_data\\] table. All tasks returned from this query are considered during the template evaluation. **Note:** Even if a task is returned as a part of the query, it doesn’t guarantee that the template run processes the task. Other factors might cause the task to be skipped during template processing.\n\nFor details, see [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).\n\n</td></tr></tbody>\n</table><table id=\"table_sl4_t5c_txb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the template was updated.\n\n Valid values:\n\n-   true: The template was updated.\n-   false: The template was updated. The template might not be in draft \\(unpublished\\) state.\n\n</td></tr></tbody>\n</table>The following example shows how to update several properties of an existing de-duplication template.\n\n```\nvar template = {\n  \"name\": \"Test Windows Template\",\n  \"table\": \"cmdb_ci_win_server\",\n  \"description\": \"This is a windows server template\",\n  \"master_ci_option\": \"newest_updated\",\n  \"master_ci_condition\": \"\",\n  \"allow_null_attribute_update\": false,\n  \"allow_master_ci_null_update\": false,\n  \"oldest_created_merge_attributes\": \"\",\n  \"newest_updated_merge_attributes\": \"ram,cpu_count\",\n  \"most_relations_merge_attributes\": \"\",\n  \"most_related_items_merge_attributes\": \"\",\n  \"merge_relations\": \"all\",\n  \"merge_relations_condition\": \"\",\n  \"merge_related_items\": \"conditional\",\n  \"merge_related_items_condition\": [\n    {\n      \"related_entry\": \"change_request.cmdb_ci\",\n      \"condition\": \"ramCONTAINS1024\"\n    },\n    {\n      \"related_entry\": \"incident.cmdb_ci\",\n      \"condition\": \"os_versionCONTAINSWindows\"\n    }\n  ],\n  \"duplicate_ci_action\": \"delete\",\n  \"duplicate_ci_updates\": \"\",\n  \"task_conditions\": \"category=attribute^key=serial_number^value=E2BX1^EQ\"\n};\n\nsn_cmdb.DuplicateTemplate.updateTemplate(<template_id>, template);\n```\n\nOutput:\n\n```\ntrue\n```\n\n"}}