Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Core ServiceNow APIs/GlideRecord/CheckDuplicate-Server/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Scan all Servers (cmdb_ci_server). For each one, check if there is another CI in cmdb_ci_computer with the same name but not a server (sys_class_name != cmdb_ci_server).

If found, log the server name and the duplicate CI’s class; keep a running duplicate count; finally log the total.

*******Descriton****
1. var gr = new GlideRecord("cmdb_ci_server");
2. Creates a record set for Server CIs.


gr.addEncodedQuery("sys_class_name=cmdb_ci_server");
3. Redundant: you’re already targeting the cmdb_ci_server table which is a class table. This filter doesn’t harm, but it’s unnecessary.


while (gr.next()) { ... }
4. Loops through each server CI.


5.Inside loop:

Query cmdb_ci_computer for records with the same name but where sys_class_name != cmdb_ci_server.
6. If found, log the duplicate and increment dupCount.



7. Finally logs total dupCount.
17 changes: 17 additions & 0 deletions Core ServiceNow APIs/GlideRecord/CheckDuplicate-Server/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var dupCount = 0;
var gr = new GlideRecord("cmdb_ci_server");
//gr.addQuery("name", "value");
gr.addEncodedQuery("sys_class_name=cmdb_ci_server");
gr.query();
while (gr.next()) {
var dup = new GlideRecord("cmdb_ci_computer");
dup.addQuery("name", gr.name);
dup.addQuery("sys_class_name", "!=", "cmdb_ci_server");
dup.query();
if (dup.next()) {
gs.log("\t" + gr.name + "\t" + dup.sys_class_name);
dupCount++;
}

}
gs.log("dup count=" + dupCount);
Loading