Mutliple asset records got created automatically.


Description

Sometimes there will be number of assets that will be created automatically with some 'ABC' user. The user would have just created a hardware model and that would in turn triggered asset creation.

Why the assets would get created automatically and how to avoid this.

Release or Environment

All Versions.

Cause

The below business rule is being called when there an insertion of update happening on "cmdb_hardware_product_model" table.

 updateAssetsOnCategory();

function updateAssetsOnCategory() {
var categories = (current.cmdb_model_category + '').split(',');
var old = (previous.cmdb_model_category + '');
for (var check in categories) {
if (old.indexOf(categories[check]) < 0) {
var ac = new AssetandCI();
ac.createMultipleAssets(categories[check]);
}
}
}

createMultipleAssets : function(categoryId) {
var category= new GlideRecord('cmdb_model_category');
category.query("sys_id", categoryId);

if (!category.next() || category.asset_class.nil() || category.enforce_verification || category.cmdb_ci_class == '')
return;

var ci = new GlideRecord(category.cmdb_ci_class);
if (!ci.isValid()) return;
ci.addQuery('asset', '').addOrCondition('asset', null);
ci.addQuery('model_id.cmdb_model_category', 'CONTAINS', category.sys_id);
ci.query();

while (ci.next()) {
if (ci.model_id != null && !ci.model_id.nil() && ci.model_id.asset_tracking_strategy == 'do_not_track')
continue;
var asset = new GlideRecord(category.asset_class);
asset.initialize();
asset.ci = ci.sys_id;
asset.model_category = category.sys_id;
// inherit values from CI for shared fields
var sync = new AssetAndCISynchronizer();
sync.syncRecordsWithoutUpdate(ci, asset, 'alm_asset', true);
// insert assert record and stick its reference in the CI
ci.asset = asset.insert();
ci.update();
}

Resolution

  1. The CIs will have a model_id field that points to a particular cmdb_hardware_product_model record and they may or may not have assets linked to them.
  2. When a particular model is created/modified, its "Model category" is matched against all the CIs which has the same "Model Category"(linked via CI's model_id field).
  3. If there is no "Asset" already present to these specific CIs, the intended behavior is to create the asset depending on cmdb_hardware_product_model configuration "Asset tracking strategy".
  4. If you select "Don't create Asset" on the Model record, then the Assets will not get created.
  5. Otherwise, the asset will be created for the CIs.