---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# CMDBDuplicateTemplateUtil - Global

# CMDBDuplicateTemplateUtil - Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 4 minutes to read

The CMDBDuplicateTemplateUtil script include provides methods to add and remove de-duplication tasks to/from a de-duplication template.

For more information on de-duplication of CIs, de-duplication tasks, and de-duplication templates, see [Duplicate CIs remediation](https://www.servicenow.com/docs/access?context=de-duplication-tasks&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US).

## CMDBDuplicateTemplateUtils - CMDBDuplicateTemplateUtils() {#ariaid-title2}

Creates an instance of the CMDBDuplicateTemplateUtils class.
{#CDupTempU-CMDBDupTemplateUtils__table_bhp_st5_xxb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#CDupTempU-CMDBDupTemplateUtils__table_bhp_st5_xxb}  
The following code example shows how to call this method to create a CMDBDuplicateTemplateUtils object.


    var dupTemp = new CMDBDuplicateTemplateUtils();

## CMDBDuplicateTemplateUtils - addTasksToTemplate(String templateId, Array taskIds) {#ariaid-title3}

Adds one or more de-duplication tasks to a specified de-duplication template.
This method overwrites any existing template values, but logs the previous values for each template in the system logs.  
The following list describes scenarios where a task isn't added to a template and is then marked as either skipped or failed:

* The specified template isn't in the published state. All tasks are marked as skipped.
* The specified template is running. All tasks are marked as skipped.
* The task isn't in the open state. The task is marked as skipped.
* 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.
* The specified template doesn't exist. All tasks are marked as failed.
* The GlideRecord update for the template column on the task fails. The task is marked as failed.
{#CDupTempU-addTasksToTemplate_S_A__ul_b45_fmh_yxb}
{#CDupTempU-addTasksToTemplate_S_A__table_tch_4y5_xxb__entry__3}

| Name | Type | Description |
|-|-|-|
| templateId | String | Sys_id of the de-duplication template to associate with the de-duplication task. |
| taskIds | Array | List of sys_ids of the de-duplication tasks to associate with the specified template. |
[Table 2. Parameters]

{#CDupTempU-addTasksToTemplate_S_A__table_tch_4y5_xxb} {#CDupTempU-addTasksToTemplate_S_A__table_uch_4y5_xxb__entry__2}

| Type | Description |
|-|-|
| Object | Result object containing the status of all the tasks that were attempted to be associated with the specified template. Data type: Object { "failed": [Array], "skipped": [Array], "success": [Array], "summary": "String" } |
| failed | List of tasks that failed to be associated with the template. Data type: Array of Objects "failed": [ { "message": "String", "messageType: "String", "taskId": "String" } ] |
| failed.message | Message that describes why the task failed to be associated with the template. Data type: String |
| failed.messageType | Reason for the failure. Data type: String |
| failed.taskId | Sys_id of a task that failed to be associated with the template. Data type: String |
| skipped | List of tasks that didn't fail, but weren't associated with the template (skipped). Data type: Array of Objects "skipped": [ { "message": "String", "messageType: "String", "taskId": "String" } ] |
| skipped.message | Message that describes why the task was skipped. Data type: String |
| skipped.messageType | Reason for the task being skipped. Data type: String |
| skipped.taskId | Sys_id of a task that the method skipped associated with the template. Data type: String |
| success | List of tasks that were successfully associated with the template. Data type: Array of Objects "success": [ { "message": "String", "messageType: "String", "taskId": "String" } ] |
| success.message | Not currently in use. Data type: String |
| success.messageType | Not currently in use. Data type: String |
| success.taskId | Sys_id of a task that was associated with the template. Data type: String |
| summary | Brief description of any overall processing errors that occurred, such as if the specified template doesn't exist. Data type: String |
[Table 3. Returns]

{#CDupTempU-addTasksToTemplate_S_A__table_uch_4y5_xxb}  
The following code example shows how to call this method to add de-duplication tasks to a de-duplication template.

    // Add tasks to template
    var taskIds = [];
    taskIds.push("96d2d25113152200eef2dd828144b0a4");
    taskIds.push("f785a2c3d7012201de92a5f75e610398");
    taskIds.push("635dd3dbc128ce0100655f1ec66ed41d");

    var result = new CMDBDuplicateTemplateUtils().addTasksToTemplate("6b43105c37301000deeabfc8bcbe5db2", taskIds);
    ); 
    gs.info('Success: ' + result.success);
    gs.info('Failed: ' + result.failed);
    gs.info('Skipped: ' + result.skipped);
    gs.info(Summary: ' + result.summary);

Output:

    Success: [
        {
          "taskId": "f785a2c3d7012201de92a5f75e610398",
          "message": "",
          "messageType": ""
        }
      ]
    Failed: [
        {
          "taskId": "96d2d25113152200eef2dd828144b0a4",
          "message": "Failed to add task 96d2d25113152200eef2dd828144b0a4 to template 6b43105c37301000deeabfc8bcbe5db2 because there were update errors.",
          "messageType": "update_failed"
        }
      ]
    Skipped: [
        {
          "taskId": "635dd3dbc128ce0100655f1ec66ed41d",
          "message": "Cannot add de-duplication task(s) to template 6b43105c37301000deeabfc8bcbe5db2 because the template is not published. Publish the template before adding tasks.",
          "messageType": "unpublished_template"
        }
      ]
    Summary:

## CMDBDuplicateTemplateUtils - removeTemplateFromTask(Array taskIds) {#ariaid-title4}

Clears 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.
The following list describes scenarios where the template value isn't removed from the task record and is marked as either skipped or failed:

* The de-duplication template associated with the task is running. The task is marked as skipped.
* The task state is "work in progress" or the task isn't found. The task is marked as skipped.
* The GlideRecord update for the template column on the task fails. The task is marked as failed.
{#CDupTempU-removeTemplateFromTasks_A__table_pn5_g3v_xxb__entry__3}

| Name | Type | Description |
|-|-|-|
| taskIds | Array | List of sys_ids of the de-duplication task records from which to clear the de-duplication template value. |
[Table 4. Parameters]

{#CDupTempU-removeTemplateFromTasks_A__table_pn5_g3v_xxb} {#CDupTempU-removeTemplateFromTasks_A__table_qn5_g3v_xxb__entry__2}

| Type | Description |
|-|-|
| Object | Result object containing the count of tasks for which the template value removal was successful, skipped, or failed. { "failed": Number, "success": Number, "skipped": Number } |
| failed | Number of tasks that failed to remove the de-duplication template value. Data type: Number |
| success | Number of tasks that successfully removed the de-duplication template value. Data type: Number |
| skipped | Number of tasks that the method skipped removing the de-duplication template value. Data type: Number |
[Table 5. Returns]

{#CDupTempU-removeTemplateFromTasks_A__table_qn5_g3v_xxb}  
The following code example shows how to call this method to remove de-duplication template values from de-duplication task records.

    // Remove tasks from template
    var taskIds = [];
    taskIds.push("96d2d25113152200eef2dd828144b0a4");
    taskIds.push("f785a2c3d7012201de92a5f75e610398");
    taskIds.push("635dd3dbc128ce0100655f1ec66ed41d");

    var result = new CMDBDuplicateTemplateUtils().removeTemplateFromTasks(taskIds);
    ); 
    gs.info('Success: ' + result.success);
    gs.info('Failed: ' + result.failed);
    gs.info('Skipped: ' + result.skipped);

Output:

    Success: 2
    Failed: 0
    Skipped: 1


