Fix Script for Duplicate Hardware Models referencing non existent Company recordsSummary<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } When Normalization Data Services (NDS) is implemented incorrectly or it's Guided Setup wasn't completed you may experience duplicate Model [cmdb_model] records being created where the Model Name and Model Number are the same and the Manufacturer appears to be (empty). However, grouping these duplicate model records by Manufacturer or showing the XML of the record shows that there's a Sys Id with no display value in the model's manufacturer field. Because there's no display value, the Manufacturer field on the mode list 'appears' to be (empty).If you query the Company [core_company] table for a record with the Sys Id from the Model's manufacturer field, you'll find there's no such record, and thus the Model record is referencing a non existent Company record.This is typically a 'symptom' of an incorrect/incomplete NDS setup resulting in Company records with invalid unique Hash values or their Normalized field incorrectly set to true or false.When Company records are in this state, Discovery or any other data source that uses the MakeAndModel API to get existing or create new Models for CIs being brought into the CMDB will query NDS for a normalized Company record for the discovered manufacturer name and will create a new Company record if a 'normalized' company isn't returned.Due to incorrect/incomplete NDS setup, the MakeAndModel API will try to create a new Company record that already exists and the insert of the new company record will fail with a UNIQUE Key Violation in the backend DataBase.This leaves the Sys ID for the Company record that was being created in the Model's manufacturer field and no Company with that Sys ID created.This occurs each time that same Manufacturer and Model are discovered, and a duplicate Hardware Model is created. The custom Script Include attached to this article has helper functions that can be called from a background script to use the below strategies to try and get the Manufacturers of the Models using the Model's name and then update the Model with that Company [core_company] record. 1. Look for the Model's name on the SNMP OID Classification [discovery_snmp_oid] table and return the Manufacturer.2. Look for other Model records with same Model name AND have the existing Company/Manufacturer.3. A Model's Display Name is usually the manufacturer name + the model name, so try and parse the manufacturer name from the Display name.4. Finally, if no Manufacturer found then the script will log which Models need to be verified and set manually. Facts<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } The Attached Script Include ModelCleanUpUtil needs to be imported to your instance for the background script examples in this article to work. Release<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } All Releases Instructions<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } I. Import the attached Script Include ModelCleanUpUtil 1. Download file sys_script_include_ModelCleanUpUtil.xml attached to this KB. 2. Go to the Script Includes [sys_script_include] table on your instance. 3. Right Click the Column Headers at the top of the list. 4. Click Import XML. 5. Click Choose File and select sys_script_include_ModelCleanUpUtil.xml. 6. Click Upload. II. Running the Script 1. Go to the Model [cmdb_model] table. 2. Filter the table for records where Manufacturer Is Not Empty AND Manufacturer.Name Is Empty to get all of the Models referencing a non existent Company. 3. Add further filter conditions to split the number of records to be updated into smaller batches. For Example: Name Starts with A 4. After the list has been filtered, right click on the breadcrumb filter and select Copy Query. Example of a copied query: "manufacturerISNOTEMPTY^manufacturer.nameISEMPTY^nameSTARTSWITHA" 5. Go to System Definition > Scripts - Background 6. Copy and paste the below script and add the copied Encoded Query to the input before running it. // 1. Add an Encoded Query from the Model [cmdb_model] table var encodedQuery = ""; // 2. Click the 'Run Script' button // Please do not edit below this line var modelCleanup = new ModelCleanUpUtil(); modelCleanup.fixHardwareModels(encodedQuery); // Please do not edit above this line 7. Click Run Script. 8. After the script completes refresh the filtered Models list and check the results. 9. Any remaining Models still referencing an non existent Company will need to be verified manually. III. Updating multiple Models after verifying the Company manually. After you've identified the manufacturer. 1. Go to the Model [cmdb_model] table. 2. Filter the table for records where Manufacturer Is Not Empty AND Manufacturer.Name Is Empty. 3. Add further filter conditions to specify only the records that are going to be updated with that Manufacturer. 4. After the list has been filtered, right click on the breadcrumb filter and select Copy Query. 5. Go to System Definition > Scripts - Background 6. Copy and paste the below script and add the Manufacturer Name and the copied Encoded Query to the input before running it. // 1. Add the Manufacturers Name and the Encoded Query from the Model [cmdb_model] table below var manufacturerName = ""; var encodedQuery = ""; // 2. Click the 'Run Script' button // Please do not edit below this line var modelCleanup = new ModelCleanUpUtil(); modelCleanup.directlyUpdateMfr(manufacturerName,encodedQuery); // Please do not edit above this line 7. Click Run Script. 8. After the script completes refresh the filtered Models list and check the results.