Delete Duplicate CI

mike2agk
Tera Contributor

Hello, i have issues  with getting duplicate CI's deleted. i have a script below inserted in a workflow editor so that once i click the task that contains the duplicate Ci and then Remediate button, the scripts runs and deletes the duplicate. I see this works fine with just 2 CI's {of which one is a duplicate}. if i have more than one duplicate CI lets say 7  it just deletes only 1. Looking below, it just deleted the CI associated with  03-23-2018 . I guess its not going beyond the second created  [Order By Descending] while deleting. I have also included the script for your review

03-13-2018

02-23-2018

03-14-2018

01-12-2018

03-23-2018

01-12-2018

03-24.2018

script:

var grResult = new GlideRecord ( 'duplicate_audit_result');
grResult.addQuery ( 'follow_on_task', current.sys_id );
grResult.query();
var cis = [];
while (grResult.next())
cis.push(grResult.getValue('duplicate_ci'));
var grCi = new GlideRecord ( 'cmdb_ci' );
grCi.addQuery ('sys_id', 'IN', cis.toString());
grCi.orderByDesc ('sys_created_on');
grCi.query();
grCi.next();
while (grCi.next())
grCi.deleteRecord();

9 REPLIES 9

Hello Varsha,

I really appreciate all your responses. yes I do have duplicates in cmdb_ci table. I'm  populating data in the cmdb_ci table by using Discovery. To explain the history of what I have. in my instance[Kingston] I have a widget Duplicate CI which captures the duplicates via [cmdb view>Duplicate CI's]

find_real_file.png

once I click on any bar chart I'm taken to the duplicate records/tasks for the CI class. Then my original question will breakdown the setup{workflow editor script etc]

I would like a situation where by since im not deleting the CI anymore{which will remove it frm everywhere e.g cmdb_ci table, duplicate list etc] im making it obsolete and inactive

The goal is to make the CI no longer a duplicate[

[My instance is [glide-kingston-10-17-2017__patch4-03-21-2018]

The below script{Just temporary and still work in progress} when run updates the cmdb_ci with operational status to (6) instead of 'Retired' do you know why?

var grResult = new GlideRecord ( 'duplicate_audit_result');
grResult.addQuery ( 'follow_on_task', current.sys_id );
grResult.query();
var cis = [];
while (grResult.next())
cis.push(grResult.getValue('duplicate_ci'));


var grCi = new GlideRecord ( 'cmdb_ci' );
grCi.addQuery ('sys_id', 'IN', cis.toString());
grCi.orderByDesc ('sys_created_on');
grCi.query();
grCi.next();
while (grCi.next())  {
// grCi.deleteRecord();
grCi.setValue("operational_status" , "6");
grCi.update();

}

 

Hi mike,

 

use the bellow script:--

var grResult = new GlideRecord ( 'duplicate_audit_result');
grResult.addQuery ( 'follow_on_task', current.sys_id );
grResult.query();
var cis = [];
while (grResult.next())
cis.push(grResult.getValue('duplicate_ci'));


var grCi = new GlideRecord ( 'cmdb_ci' );
grCi.addQuery ('sys_id', 'IN', cis.toString());
grCi.orderByDesc ('sys_created_on');
grCi.query();
grCi.next();
while (grCi.next())  {
// grCi.deleteRecord();
grCi.setValue("install_status" , "7");
grCi.update();

}

just i modified one sentence

grCi.setValue("install_status" , "7");

 because  operational status is used in service mapping and install_status is used in cmdb_ci.so we need to change install_status to 'retired' for the particular ci.

if it wont work,please let me know.

 

 

if useful mark it correct and useful.

 

 

Regards,

Varsha.

 

 

 

Thanks for your response unfortunately that did not work . What I had to do was to check the "choices" tab  in the dictionary entry/operation status field in the CI duplicate form. The choice tab will give u the different equivalents

find_real_file.png

dheepas
Kilo Explorer

Hi Mike

 

I am also  trying to retire the duplicate CI but the script is not working .

 

var grResult = new GlideRecord ( 'duplicate_audit_result');
grResult.addQuery ( 'follow_on_task', current.sys_id );
grResult.query();
var cis = [];
while (grResult.next())
cis.push(grResult.getValue('duplicate_ci'));

var grCi = new GlideRecord ( 'cmdb_ci' );
grCi.addQuery ('sys_id', 'IN', cis.toString());
grCi.orderByDesc ('sys_created_on');
grCi.query();
grCi.next();
while (grCi.next()) {
// grCi.deleteRecord();
grCi.setValue("install_status" , "3");
grCi.update();

}

 

I found that "install_status" choice is different in london version for cmdb_ci table.   Please let me know how do you fix the issue

Nasrullah
Kilo Guru

Remediating duplicate CI requires you to not just retire/delete the duplicated CI, but you also need to set the de-duplication task as active=false and state=3 (Closed Completed).