
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 06-24-2021 06:01 PM
Hello Everyone,
I would like to share one of my work that might helpful to my fellow ServiceNow colleagues i.e. ‘No Duplicate CI in CMDB’, which means stop the creation and cleanup the existing one.
Notes:-
1) Generally my articles are lengthy in nature as I try to give all details, so whoever goes through it get all details and able to complete the job end to end.
So, please be patient and take some time to go over my articles.
2) I am just sharing my way of completion and being owner of ‘very less ego’ & ‘always learner mentality’ I welcome for ‘feedback’. So, please feel free to comment on my articles without any hesitation.
Step by Step Details
First Step – Build a strong IRE rule for each CI class
The very first step is to build a strong IRE rule and there can be either of the 2 ways to accomplish a strong ‘Identification’ part as below -
1) Replace the ‘derived Identification rule’ with a custom build ‘Identification rule’ for that particular class.
OR
2) Keep the ‘derived Identification rule’ and add ‘Inclusion Rule (Advanced)’ to narrow down the identification of the CI.
Now, Irrelevant of choosing either option – 1 or option – 2 for a strong ‘Identification rule’ strong ‘Reconciliation Rules’ and ‘Data Refresh Rules’ reduce duplicate creation chance more.
Second Step – Stop manually created duplicates
Create a ‘before’ business rule as per below screenshots. I am giving the sample of ‘Windows Server table’ (cmdb_ci_win_server) and considering ‘name’ as unique identifier for of ‘Windows Server table’. So if anyone tries to manually create a ‘Windows Server’ with the same name that already exists then it will be blocked. Though it has been shown on a single field in my example but it can be extended to any number of fields. So, please change it as per your requirement.
Script for Business Rule
(function executeRule(current, previous /*null when async*/) {
var nodup = new GlideRecord('cmdb_ci_win_server');
nodup.addQuery('name='+current.name);
nodup.setLimit(1);
nodup.query();
if(nodup.next()) {
gs.addErrorMessage("This will create a duplicate record,so insertion is aborted");
current.setAbortAction(true);
}
})(current, previous);
Third Step – Cleaning up existing and future duplicates
Even after rigid first 2 steps in future duplicates can get created and/or you have existing duplicates in the system and this step will help you on both the scenarios.
Now, please create a simple workflow as below on table - reconcile_duplicate_task.
Please put the below script within the ‘Run Script’ mentioned in the above workflow.
Script
// Find all duplicate records associated with the current task
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'));
// Query for the duplicate records, and order in reverse chronological order
var grCi = new GlideRecord ( 'cmdb_ci_win_server' );
grCi.addQuery ('sys_id', 'IN', cis.toString());
grCi.orderByDesc ('sys_created_on');
grCi.query();
grCi.next(); // Skip the CI that was created first
while (grCi.next()) {
grCi.operational_status = '2';
grCi.update();
}
// Mark the de-dup task to closed complete
current.state = '3';
Please open any of your existing duplicate task.Say for example I am giving the below sample –
Now, Click on ‘Remediate’ button which will bring the below screen.
Then select the options as above and click on ‘Next’ and fillup the section like below screenshot
Thanks!!
- 2,108 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hey @Ankan Mukherje1 ,
This is great content!
I have some queries related to duplicate CI remediation.
I have some records in "duplicate_audit_result" with empty values for field "follow_on_task".
I am not sure what caused this, may be the de-duplication task don't exist anymore?
We have around 4k+ de-duplication tasks and most of these are created 3-4 years back.
We are planning to force delete all these de-duplication tasks and let it regenerate.(hoping that it will reduce the count).
I need to understand the relation between de-duplication task and duplicate_audit_result.
Also, I see that your are using custom workflow to remediate de-duplication tasks manually.
Is there any better approach to remediate large number of such tasks?
How do we go forward with this situation?
Any advice will be very helpful.
Thank you.