How to run de-duplication task in bulk?

nikhil2810
Tera Contributor

We have a thousands of CMDB de-duplication tasks and needed a way to automate it.

Please suggest a way to do so?

3 REPLIES 3

Erik Gunther2
Kilo Guru

You could write a script that sorts by the field(s) that indicate a duplicate task, then loop through the entire set.

 

var gr = new GlideRecord('task');

gr.addEncodedQuery('parentISEMPTY');  //Avoid deleting tasks that have a parent reference to another record

gr.orderBy('sys_class_name');

gr.orderBy('short_description'); //Indicates second sort by column

gr.query();

 

gr.next();

var previousKey = gr.sys_class_name + ';' + gr.short_description;

 

while (gr.next()) {

   var key = gr.sys_class_name + ';' + gr.short_description;

   if (previousKey = key) {

      //duplicate

      gr.deleteRecord();

   }

   else {

      //not duplicate

      previousKey = key;

   }

}

 

Notes:

* I haven't tested this script but it illustrates the approach

* I'm not sure if a set of duplicate records will have one Task with a Parent value and the other is null. But I provide at least a way you may be able to prevent deleting tasks with references to other records.

 

I hope this helps.

 

Hi Erik,

It is to reconcile the CMDB CI de-duplication task and how can I run them automatically.

Sorry if you misunderstood the question 

Erik Gunther2
Kilo Guru

I should add, you could run this from the "Scripts - Background" form. You could also create a script include and call it from a scheduled job.

 

Note: I'm not sure why you would have duplicate tasks, but resolving this at the root cause is key.

 

If any of this was helpful, please indicate in this thread. Thanks.