From ad4324f630d36dd730ed5b1ed0700428314dfc26 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 22 Oct 2025 15:40:38 +0530 Subject: [PATCH 1/8] 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/8] 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/8] 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/8] 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 a3e54e01cb88ddc2f94f16df6ca8f48a9fe40aa3 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 22 Oct 2025 17:06:29 +0530 Subject: [PATCH 5/8] Create TechTrekwithAJ-AutoPopulateMissingManufacturer.js This script is used in ServiceNow to automatically fill in the missing manufacturer information for Configuration Items (CIs) in the CMDB (Configuration Management Database). --- ...TechTrekwithAJ-AutoPopulateManufacturer.js | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Specialized Areas/CMDB/CMDB Utility Scripts/TechTrekwithAJ-AutoPopulateManufacturer.js diff --git a/Specialized Areas/CMDB/CMDB Utility Scripts/TechTrekwithAJ-AutoPopulateManufacturer.js b/Specialized Areas/CMDB/CMDB Utility Scripts/TechTrekwithAJ-AutoPopulateManufacturer.js new file mode 100644 index 0000000000..ef1f243c60 --- /dev/null +++ b/Specialized Areas/CMDB/CMDB Utility Scripts/TechTrekwithAJ-AutoPopulateManufacturer.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 6b86e39f4018e476b70124324e3b129d7b479043 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 22 Oct 2025 17:07:10 +0530 Subject: [PATCH 6/8] Create TechTrekwithAJ-AutoPopulateMissingManufacturerReadME.md This script is used in ServiceNow to automatically fill in the missing manufacturer information for Configuration Items (CIs) in the CMDB (Configuration Management Database). --- ...AJ-AutoPopulateMissingManufacturerReadME.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Specialized Areas/CMDB/CMDB Utility Scripts/TechTrekwithAJ-AutoPopulateMissingManufacturerReadME.md diff --git a/Specialized Areas/CMDB/CMDB Utility Scripts/TechTrekwithAJ-AutoPopulateMissingManufacturerReadME.md b/Specialized Areas/CMDB/CMDB Utility Scripts/TechTrekwithAJ-AutoPopulateMissingManufacturerReadME.md new file mode 100644 index 0000000000..072ea0e347 --- /dev/null +++ b/Specialized Areas/CMDB/CMDB Utility Scripts/TechTrekwithAJ-AutoPopulateMissingManufacturerReadME.md @@ -0,0 +1,18 @@ +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 0ced2c9dbaf95b7a14a25ac8cd6d433b43a213f8 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 22 Oct 2025 17:09:56 +0530 Subject: [PATCH 7/8] 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 5571c71b98fcff8451393aca6685309d5068140d Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 22 Oct 2025 17:24:53 +0530 Subject: [PATCH 8/8] Rename TechTrekwithAJ-AutoPopulateMissingManufacturerReadME.md to ReadME.md --- ...kwithAJ-AutoPopulateMissingManufacturerReadME.md => ReadME.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Specialized Areas/CMDB/CMDB Utility Scripts/{TechTrekwithAJ-AutoPopulateMissingManufacturerReadME.md => ReadME.md} (100%) diff --git a/Specialized Areas/CMDB/CMDB Utility Scripts/TechTrekwithAJ-AutoPopulateMissingManufacturerReadME.md b/Specialized Areas/CMDB/CMDB Utility Scripts/ReadME.md similarity index 100% rename from Specialized Areas/CMDB/CMDB Utility Scripts/TechTrekwithAJ-AutoPopulateMissingManufacturerReadME.md rename to Specialized Areas/CMDB/CMDB Utility Scripts/ReadME.md