diff --git a/Core ServiceNow APIs/GlideRecord/CheckDuplicate-Server/readme.md b/Core ServiceNow APIs/GlideRecord/CheckDuplicate-Server/readme.md new file mode 100644 index 0000000000..2f8e0eec15 --- /dev/null +++ b/Core ServiceNow APIs/GlideRecord/CheckDuplicate-Server/readme.md @@ -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. diff --git a/Core ServiceNow APIs/GlideRecord/CheckDuplicate-Server/script.js b/Core ServiceNow APIs/GlideRecord/CheckDuplicate-Server/script.js new file mode 100644 index 0000000000..39b9812167 --- /dev/null +++ b/Core ServiceNow APIs/GlideRecord/CheckDuplicate-Server/script.js @@ -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);