Best Practise to handle Orphan CIs

SarthakShri21
Tera Contributor

Hello All,

Can anyone suggest a practice to handle Orphan CIs.

 

Kind Regards,

SarthsShri21

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

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.

See here: https://docs.servicenow.com/bundle/washingtondc-servicenow-platform/page/product/configuration-manag...

 

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:

https://docs.servicenow.com/bundle/washingtondc-servicenow-platform/page/product/configuration-manag...

 

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

View solution in original post

4 REPLIES 4

Robbie
Kilo Patron
Kilo Patron

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.

See here: https://docs.servicenow.com/bundle/washingtondc-servicenow-platform/page/product/configuration-manag...

 

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:

https://docs.servicenow.com/bundle/washingtondc-servicenow-platform/page/product/configuration-manag...

 

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

Thanks @Robbie for the information you share Robbie...

Its helpful for me...

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

AJ-TechTrek
Giga Sage
Giga Sage

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/