Delete Duplicate CI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2018 12:06 PM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2018 12:56 PM
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]
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 02:09 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 08:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2019 02:59 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2020 09:10 PM
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).