From ad4324f630d36dd730ed5b1ed0700428314dfc26 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 22 Oct 2025 15:40:38 +0530 Subject: [PATCH 1/9] Create TechTrekwithAJ-PopulateManufacturer.js This code will help to populate the Manufacturer if that empty on CMDB_CI table --- CMDB/TechTrekwithAJ-PopulateManufacturer.js | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 CMDB/TechTrekwithAJ-PopulateManufacturer.js diff --git a/CMDB/TechTrekwithAJ-PopulateManufacturer.js b/CMDB/TechTrekwithAJ-PopulateManufacturer.js new file mode 100644 index 0000000000..5fbb598dff --- /dev/null +++ b/CMDB/TechTrekwithAJ-PopulateManufacturer.js @@ -0,0 +1,46 @@ +// Predefined mapping of model names to manufacturer sys_ids or names +var modelManufacturerMap = { + 'ThinkPad T14': 'Lenovo', + 'EliteBook 840': 'HP', + 'Latitude 7420': 'Dell', + 'MacBook Pro 16': 'Apple', + 'Surface Pro 7': 'Microsoft' +}; + +// Function to get the manufacturer sys_id from the manufacturer name +function getManufacturerSysId(name) { + var mfgGR = new GlideRecord('core_company'); + mfgGR.addQuery('name', name); + mfgGR.query(); + if (mfgGR.next()) { + return mfgGR.getUniqueValue(); + } + return null; +} + +// GlideRecord to loop through Configuration Items where manufacturer is empty +var ciGR = new GlideRecord('cmdb_ci'); +ciGR.addNullQuery('manufacturer'); // Manufacturer is empty +ciGR.query(); + +var updatedCount = 0; + +while (ciGR.next()) { + var model = ciGR.model.name.toString(); // Get model name + + if (model && modelManufacturerMap.hasOwnProperty(model)) { + var manufacturerName = modelManufacturerMap[model]; + var manufacturerSysId = getManufacturerSysId(manufacturerName); + + if (manufacturerSysId) { + ciGR.manufacturer = manufacturerSysId; + ciGR.update(); + updatedCount++; + gs.info('Updated CI: ' + ciGR.name + ' | Model: ' + model + ' | Manufacturer: ' + manufacturerName); + } else { + gs.warn('Manufacturer "' + manufacturerName + '" not found in core_company table.'); + } + } +} + +gs.info('Auto-populate complete. Total CIs updated: ' + updatedCount); From 88951259d69802e97cf6e00950b247cc734bbc4e Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 22 Oct 2025 15:43:15 +0530 Subject: [PATCH 2/9] Create TechTrekwithAJ-PopulateManufacturerReadME.md --- ...chTrekwithAJ-PopulateManufacturerReadME.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 CMDB/TechTrekwithAJ-PopulateManufacturerReadME.md diff --git a/CMDB/TechTrekwithAJ-PopulateManufacturerReadME.md b/CMDB/TechTrekwithAJ-PopulateManufacturerReadME.md new file mode 100644 index 0000000000..a02a97889d --- /dev/null +++ b/CMDB/TechTrekwithAJ-PopulateManufacturerReadME.md @@ -0,0 +1,23 @@ +This script is used in ServiceNow to automatically fill in the missing manufacturer information for Configuration Items (CIs) in the CMDB (Configuration Management Database). + +1. Predefined Mapping: +The script starts with a list of known model names and their corresponding manufacturer names. +For example, a model called ThinkPad T14 is made by Lenovo, and MacBook Pro 16 is made by Apple + +2. Look Up Manufacturer: + * It defines a function that looks up the manufacturer’s record in the core_company table (based on the name) and gets its unique ID (sys_id). + +3. Find CIs Missing a Manufacturer: + * The script goes through all CIs in the cmdb_ci table where the manufacturer field is empty. + +4. Update Missing Manufacturer: + * For each of those CIs: + * It checks the model name. + * If the model is in the predefined mapping: + * It looks up the correct manufacturer in the core_company table. + * It updates the CI record by setting the manufacturer field with the correct sys_id. + * It also logs that the update was successful. + * If the manufacturer is not found in the system, it logs a warning. + +5. Final Log: + * After going through all matching CIs, it logs how many records were successfully updated. From 176e80dceacd9800398956fd3ce3b3f50e61519e Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 22 Oct 2025 15:52:23 +0530 Subject: [PATCH 3/9] Delete CMDB/TechTrekwithAJ-PopulateManufacturerReadME.md --- ...chTrekwithAJ-PopulateManufacturerReadME.md | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 CMDB/TechTrekwithAJ-PopulateManufacturerReadME.md diff --git a/CMDB/TechTrekwithAJ-PopulateManufacturerReadME.md b/CMDB/TechTrekwithAJ-PopulateManufacturerReadME.md deleted file mode 100644 index a02a97889d..0000000000 --- a/CMDB/TechTrekwithAJ-PopulateManufacturerReadME.md +++ /dev/null @@ -1,23 +0,0 @@ -This script is used in ServiceNow to automatically fill in the missing manufacturer information for Configuration Items (CIs) in the CMDB (Configuration Management Database). - -1. Predefined Mapping: -The script starts with a list of known model names and their corresponding manufacturer names. -For example, a model called ThinkPad T14 is made by Lenovo, and MacBook Pro 16 is made by Apple - -2. Look Up Manufacturer: - * It defines a function that looks up the manufacturer’s record in the core_company table (based on the name) and gets its unique ID (sys_id). - -3. Find CIs Missing a Manufacturer: - * The script goes through all CIs in the cmdb_ci table where the manufacturer field is empty. - -4. Update Missing Manufacturer: - * For each of those CIs: - * It checks the model name. - * If the model is in the predefined mapping: - * It looks up the correct manufacturer in the core_company table. - * It updates the CI record by setting the manufacturer field with the correct sys_id. - * It also logs that the update was successful. - * If the manufacturer is not found in the system, it logs a warning. - -5. Final Log: - * After going through all matching CIs, it logs how many records were successfully updated. From ef7e37e6c416df2e4383da1b6ee615aa05b4d476 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 22 Oct 2025 16:37:15 +0530 Subject: [PATCH 4/9] Update TechTrekwithAJ-PopulateManufacturer.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This script is used in ServiceNow to automatically fill in the missing manufacturer information for Configuration Items (CIs) in the CMDB (Configuration Management Database). 1. Predefined Mapping: The script starts with a list of known model names and their corresponding manufacturer names.For example, a model called ThinkPad T14 is made by Lenovo, and MacBook Pro 16 is made by Apple 2. Look Up Manufacturer: * It defines a function that looks up the manufacturer’s record in the core_company table (based on the name) and gets its unique ID (sys_id). 3. Find CIs Missing a Manufacturer: * The script goes through all CIs in the cmdb_ci table where the manufacturer field is empty. 4. Update Missing Manufacturer: * For each of those CIs: * It checks the model name. * If the model is in the predefined mapping: * It looks up the correct manufacturer in the core_company table. * It updates the CI record by setting the manufacturer field with the correct sys_id. * It also logs that the update was successful. * If the manufacturer is not found in the system, it logs a warning. 5. Final Log: * After going through all matching CIs, it logs how many records were successfully updated. --- CMDB/TechTrekwithAJ-PopulateManufacturer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMDB/TechTrekwithAJ-PopulateManufacturer.js b/CMDB/TechTrekwithAJ-PopulateManufacturer.js index 5fbb598dff..4da3c5d987 100644 --- a/CMDB/TechTrekwithAJ-PopulateManufacturer.js +++ b/CMDB/TechTrekwithAJ-PopulateManufacturer.js @@ -44,3 +44,7 @@ while (ciGR.next()) { } gs.info('Auto-populate complete. Total CIs updated: ' + updatedCount); + + + +//This script is used in ServiceNow to automatically fill in the missing manufacturer information for Configuration Items (CIs) in the CMDB (Configuration Management Database). From 8eb8e9ef3736563641ee9d0ea900a8c0291364ec Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 22 Oct 2025 17:20:04 +0530 Subject: [PATCH 5/9] Create TechTrekwithAJ-CheckDiscoveryStatus.js Processes a list of IPs, finds matching CIs in cmdb_ci_computer, checks their discovery history, retrieves the related Discovery Status number, and logs the results as JSON. Logs a message if no CI or history is found. --- .../TechTrekwithAJ-CheckDiscoveryStatus.js | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Specialized Areas/ITOM/Track Discovery Status/TechTrekwithAJ-CheckDiscoveryStatus.js diff --git a/Specialized Areas/ITOM/Track Discovery Status/TechTrekwithAJ-CheckDiscoveryStatus.js b/Specialized Areas/ITOM/Track Discovery Status/TechTrekwithAJ-CheckDiscoveryStatus.js new file mode 100644 index 0000000000..13780ae83c --- /dev/null +++ b/Specialized Areas/ITOM/Track Discovery Status/TechTrekwithAJ-CheckDiscoveryStatus.js @@ -0,0 +1,74 @@ +// Configuration // +// Define the list of IP addresses to check +var ipList = [ + '192.168.1.35', + '192.168.1.27', + '192.168.1.15' +]; + +// Main Script // +var results = []; + +ipList.forEach(function(ip) { + var result = { + ip_address: ip, + discovery_status_number: '' + }; + + //Find CI (Computer) with matching IP + var ciGR = new GlideRecord('cmdb_ci_computer'); + ciGR.addQuery('ip_address', ip); + ciGR.query(); + + if (ciGR.next()) { + var ciSysId = ciGR.getUniqueValue(); + + //Check if CI has an entry in discovery_device_history + var historyGR = new GlideRecord('discovery_device_history'); + historyGR.addQuery('ci', ciSysId); + historyGR.orderByDesc('sys_created_on'); + historyGR.query(); + + if (historyGR.next()) { + + //Get discovery status number (e.g., DIS123456) + var statusGR = new GlideRecord('discovery_status'); + if (statusGR.get(historyGR.discovery_status.toString())) { + result.discovery_status_number = statusGR.number.toString(); + } else { + result.discovery_status_number = 'Discovery status record not found'; + } + } else { + result.discovery_status_number = 'No discovery record found'; + } + } else { + result.discovery_status_number = 'No CI found with this IP'; + } + + results.push(result); +}); + +// Output results to system log in JSON format + +gs.info('IP to Discovery Status Mapping:\n' + JSON.stringify(results, null, 2)); + + + + +//Output// + +[ + { + "ip_address": "192.168.1.35", + "discovery_status_number": "DIS123145" + }, + { + "ip_address": "192.168.1.27", + "discovery_status_number": "DIS123189" + }, + { + "ip_address": "192.168.1.15", + "discovery_status_number": "No discovery record found" + } +] + From 032fb43499dced14f0684ae002a2d9ca60262f53 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 22 Oct 2025 17:21:27 +0530 Subject: [PATCH 6/9] Create TechTrekwithAJ-CheckDiscoveryStatusReadME.md This script is a ServiceNow troubleshooting utility designed to help administrators quickly check if specific IP addresses were successfully discovered by the Discovery process. --- .../TechTrekwithAJ-CheckDiscoveryStatusReadME.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Specialized Areas/ITOM/Track Discovery Status/TechTrekwithAJ-CheckDiscoveryStatusReadME.md diff --git a/Specialized Areas/ITOM/Track Discovery Status/TechTrekwithAJ-CheckDiscoveryStatusReadME.md b/Specialized Areas/ITOM/Track Discovery Status/TechTrekwithAJ-CheckDiscoveryStatusReadME.md new file mode 100644 index 0000000000..bfde3dbbc8 --- /dev/null +++ b/Specialized Areas/ITOM/Track Discovery Status/TechTrekwithAJ-CheckDiscoveryStatusReadME.md @@ -0,0 +1,10 @@ +Defines a list of IP addresses to check (hardcoded in the script). +Example IPs: 192.168.1.35, 192.168.1.27, 192.168.1.15. +For each IP address in the list: +It looks up the CI (Configuration Item) in the cmdb_ci_computer table with a matching IP. +If a CI is found: +It checks the discovery_device_history table to see if that CI was discovered by ServiceNow Discovery. +If discovery history exists, it finds the related Discovery Status record (discovery_status table) and gets its number (like DIS123456). +If no CI or discovery record is found, it notes the reason in the result. +Compiles all results (IP + discovery status or error message) into a list. +Prints the results in a clear JSON format in the system logs, making it easy to read and review. From 8fcb86363abdc121e1b443e362aae13cb2b13226 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 22 Oct 2025 17:27:01 +0530 Subject: [PATCH 7/9] Delete CMDB/TechTrekwithAJ-PopulateManufacturer.js --- CMDB/TechTrekwithAJ-PopulateManufacturer.js | 50 --------------------- 1 file changed, 50 deletions(-) delete mode 100644 CMDB/TechTrekwithAJ-PopulateManufacturer.js diff --git a/CMDB/TechTrekwithAJ-PopulateManufacturer.js b/CMDB/TechTrekwithAJ-PopulateManufacturer.js deleted file mode 100644 index 4da3c5d987..0000000000 --- a/CMDB/TechTrekwithAJ-PopulateManufacturer.js +++ /dev/null @@ -1,50 +0,0 @@ -// Predefined mapping of model names to manufacturer sys_ids or names -var modelManufacturerMap = { - 'ThinkPad T14': 'Lenovo', - 'EliteBook 840': 'HP', - 'Latitude 7420': 'Dell', - 'MacBook Pro 16': 'Apple', - 'Surface Pro 7': 'Microsoft' -}; - -// Function to get the manufacturer sys_id from the manufacturer name -function getManufacturerSysId(name) { - var mfgGR = new GlideRecord('core_company'); - mfgGR.addQuery('name', name); - mfgGR.query(); - if (mfgGR.next()) { - return mfgGR.getUniqueValue(); - } - return null; -} - -// GlideRecord to loop through Configuration Items where manufacturer is empty -var ciGR = new GlideRecord('cmdb_ci'); -ciGR.addNullQuery('manufacturer'); // Manufacturer is empty -ciGR.query(); - -var updatedCount = 0; - -while (ciGR.next()) { - var model = ciGR.model.name.toString(); // Get model name - - if (model && modelManufacturerMap.hasOwnProperty(model)) { - var manufacturerName = modelManufacturerMap[model]; - var manufacturerSysId = getManufacturerSysId(manufacturerName); - - if (manufacturerSysId) { - ciGR.manufacturer = manufacturerSysId; - ciGR.update(); - updatedCount++; - gs.info('Updated CI: ' + ciGR.name + ' | Model: ' + model + ' | Manufacturer: ' + manufacturerName); - } else { - gs.warn('Manufacturer "' + manufacturerName + '" not found in core_company table.'); - } - } -} - -gs.info('Auto-populate complete. Total CIs updated: ' + updatedCount); - - - -//This script is used in ServiceNow to automatically fill in the missing manufacturer information for Configuration Items (CIs) in the CMDB (Configuration Management Database). From 24596fff1e56782f0230de22b7ac8efe7085248a Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 22 Oct 2025 17:27:22 +0530 Subject: [PATCH 8/9] Rename TechTrekwithAJ-CheckDiscoveryStatusReadME.md to ReadME.md --- .../{TechTrekwithAJ-CheckDiscoveryStatusReadME.md => ReadME.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Specialized Areas/ITOM/Track Discovery Status/{TechTrekwithAJ-CheckDiscoveryStatusReadME.md => ReadME.md} (100%) diff --git a/Specialized Areas/ITOM/Track Discovery Status/TechTrekwithAJ-CheckDiscoveryStatusReadME.md b/Specialized Areas/ITOM/Track Discovery Status/ReadME.md similarity index 100% rename from Specialized Areas/ITOM/Track Discovery Status/TechTrekwithAJ-CheckDiscoveryStatusReadME.md rename to Specialized Areas/ITOM/Track Discovery Status/ReadME.md From 53504845068558b964f597b1d2e03a61ac2ae1c0 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 22 Oct 2025 18:26:37 +0530 Subject: [PATCH 9/9] Rename TechTrekwithAJ-CheckDiscoveryStatus.js to CheckDiscoveryStatus.js --- ...TrekwithAJ-CheckDiscoveryStatus.js => CheckDiscoveryStatus.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Specialized Areas/ITOM/Track Discovery Status/{TechTrekwithAJ-CheckDiscoveryStatus.js => CheckDiscoveryStatus.js} (100%) diff --git a/Specialized Areas/ITOM/Track Discovery Status/TechTrekwithAJ-CheckDiscoveryStatus.js b/Specialized Areas/ITOM/Track Discovery Status/CheckDiscoveryStatus.js similarity index 100% rename from Specialized Areas/ITOM/Track Discovery Status/TechTrekwithAJ-CheckDiscoveryStatus.js rename to Specialized Areas/ITOM/Track Discovery Status/CheckDiscoveryStatus.js