Need pending CIS which dont have relations
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
we have two tables a and b which is having relation used by::uses , 'a' is having 504911 cis whereas 'b' has 515963 and we need to find the "B" Cis which dont have relations
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
Hi @nelihiqowdg ,
There are multiple ways to do it but, i would suggest use this background script
// 1. Get all Class B sys_ids
var allB = {};
var grB = new GlideRecord('B_Table');
grB.query();
while (grB.next()) {
allB[grB.getUniqueValue()] = true;
}
// 2. Check relationships in cmdb_rel_ci
var rel = new GlideRecord('cmdb_rel_ci');
rel.addEncodedQuery('type=6afd799338a02000c18673032c71b87b') // sys_id of the Usedby :: uses , go to cmdb_rel_type to get this
rel.query();
while (rel.next()) {
var parent = rel.parent.toString();
var child = rel.child.toString();
// Remove if found as parent or child
if (allB[parent]) {
delete allB[parent];
}
if (allB[child]) {
delete allB[child];
}
}
// 3. Remaining CIs Which donot have RELATION
var noRelation = Object.keys(allB);
gs.print('Sys_ids WITHOUT relations: ' + noRelation.join(','));
This will take time and will have a large load on the instance cause you have nearly 6L CIs, So it is recommended to run this when the instance has very less traffic.
Mark it helpful if it helped you.
This will take time and will have a large load on the instance cause you have nearly 6L CIs, So it is recommended to run this when the instance has very less traffic.
Mark it helpful if it helped you.
