- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 02:09 AM
Hello All,
Can anyone suggest a practice to handle Orphan CIs.
Kind Regards,
SarthsShri21
Solved! Go to Solution.
- Labels:
-
Data Health Tools
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 03:26 AM
Hi @SarthakShri21,
Anything around CI management can quickly turn into a bigger question, so I'll try and keep this simple and focused although I would say you should first look and review the CMDB Health documentation from ServiceNow where you have several great resources such as dashboards etc.
Additionally more pertinent to your question, here's a ServiceNow Doc link on creating and setting up a CI orphan rule to manage this activity in an automated fashion:
Now to directly answer your question on orphaned records - How to count and delete orphan relationships (cmdb_rel_ci) found below as outlined in KB0750776
Here is the script that can be used to find the orphan relationship counts:
// Find orphan rel count
var ga = new GlideAggregate('cmdb_rel_ci');
ga.addEncodedQuery('parent.sys_class_path=NULL^ORchild.sys_class_path=NULL');
ga.addAggregate('COUNT');
ga.query();
ga.next();
gs.log(ga.getAggregate('COUNT'));
To delete orphan relationships
//delete orphans
var gr = new GlideRecord('cmdb_rel_ci');
gr.addEncodedQuery('parent.sys_class_path=NULL^ORchild.sys_class_path=NULL');
//gr.deleteMultiple(); //uncheck when required.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 03:26 AM
Hi @SarthakShri21,
Anything around CI management can quickly turn into a bigger question, so I'll try and keep this simple and focused although I would say you should first look and review the CMDB Health documentation from ServiceNow where you have several great resources such as dashboards etc.
Additionally more pertinent to your question, here's a ServiceNow Doc link on creating and setting up a CI orphan rule to manage this activity in an automated fashion:
Now to directly answer your question on orphaned records - How to count and delete orphan relationships (cmdb_rel_ci) found below as outlined in KB0750776
Here is the script that can be used to find the orphan relationship counts:
// Find orphan rel count
var ga = new GlideAggregate('cmdb_rel_ci');
ga.addEncodedQuery('parent.sys_class_path=NULL^ORchild.sys_class_path=NULL');
ga.addAggregate('COUNT');
ga.query();
ga.next();
gs.log(ga.getAggregate('COUNT'));
To delete orphan relationships
//delete orphans
var gr = new GlideRecord('cmdb_rel_ci');
gr.addEncodedQuery('parent.sys_class_path=NULL^ORchild.sys_class_path=NULL');
//gr.deleteMultiple(); //uncheck when required.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 04:33 AM
Thanks @Robbie for the information you share Robbie...
Its helpful for me...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 06:02 AM
Hi @SarthakShri21,
No worries at all. Let me know if you have any further questions.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 05:01 AM
Hi @SarthakShri21 ,
Please refer the below resource, might be helpful.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0829101
Please appreciate the efforts of community contributors by marking appropriate response as Mark my Answer Helpful or Accept Solution this may help other community users to follow correct solution in future.
Thanks
AJ
Linkedin Profile:- https://www.linkedin.com/in/ajay-kumar-66a91385/