jonsan09
Giga Sage
Giga Sage

After attending a recent HAM Office hours there were some questions about migrating assets to a new hardware model. I wanted to share the step I take to migrate models, and hopefully help some other folks that might have to do the same.

 

Here is the script I use, it can be used either via fix script or background script

 

var incorrectModel = "SysID of Incorrect Model";
var correctModel ="SysID of Corect Model";
var correctManufacturer = "SysID of Correct Manufacturer";
var recordLimit = "Limit of records to update, good to test 1 first before updating all records";
var delIncorrectModel = falsel; //Delete the 'incorrect" model
var updRecFields =  false; //Auto SysFields Update True or False

// ================UPDATE CONFIGURATION ITEMS (cmdb_ci)=======================

var grCI = new GlideRecord('cmdb_ci');
grCI.addQuery('model_id', incorrectModel);
grCI.setLimit(recordLimit);
grCI.setValue('model_id', correctModel);
grCI.setValue('manufacturer', correctManufacturer);
grCI.autoSysFields(updRecFields);
grCI.updateMultiple();


// ====================UPDATE HARDWARE ASSET RECORDS (alm_hardware)===========================

var grAsset = new GlideRecord('alm_hardware');
grAsset.addQuery('model', incorrectModel);
grAsset.setLimit(recordLimit);
grAsset.setValue('model', correctModel);
grAsset.autoSysFields(updRecFields);
grAsset.updateMultiple();



// ===================DELETE THE OLD MODEL RECORD ===============================
if (delIncorrectModel) {
    var delModel = new GlideRecord('cmdb_hardware_product_model');
    if (delModel.get(incorrectModel)) {
        delModel.deleteRecord();
    }

 



What the script does

 

  • It finds all Configuration Items (CIs) and Hardware Assets that are associated with a specified incorrect model SysID.

  • It updates those CIs and Assets in bulk, re-associating them with a correct model SysID and (for CIs) a correct manufacturer.

  • It uses a recordLimit variable to control how many records are updated at once, allowing for safe testing before migrating everything.

  • It includes a setting (updRecFields) to control whether system fields (like "updated on" or "updated by") are changed during this bulk update.

  • Finally, if the delIncorrectModel flag is set to true, it deletes the original "incorrect" model record from the hardware model table after the migration is complete.

 

Version history
Last update:
2 hours ago
Updated by:
Contributors