- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
3 weeks ago
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
recordLimitvariable 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
delIncorrectModelflag is set totrue, it deletes the original "incorrect" model record from the hardware model table after the migration is complete.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hey Jonson, the normalized_company, normalized_product and normalized_model field are not available to add to a list view of cmdb_model or cmdb_hardware_product_model tables. That means these fields are not available for scripting either.
How can we then find the sys_id of the incorrect model?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@AmolJ I normally grab the sys_id by going to the "Hardware Model" module from the application navigator and right clicking on the record header to copy sys_id. If you are missing the normalized fields on your hardware models, you might not have HAM Pro on your instance.
