Based on asset type need to set model category

Not applicable

Hi all,

Having a requirement, 

When ever any record is inserted into cmdb_model table 

Based on asset type (column) need to set the category which is referred to( cmdb_model_category)

 

Ex;

If asset type is laptop, TV monitor then Category should set to computer.

 

Need suggestion on it. 

 

Thanks.

3 REPLIES 3

AnveshKumar M
Tera Sage

Hi @Community Alums 

Do you have these mapping stored any where? Why because in cmdb_model_category will have a category based on CI class.

 

But as per your requirement, it is for multiple items like, Laptop & TV Monitor should be set to Computer. In this case you need to have thees mappings stored some where so that we can use as Business Rule to automatically set the category.

 

Let me know the above info.

 

Please mark my answer helpful and accept as a solution if it helped 👍

Thanks,
Anvesh

Not applicable

Hi @AnveshKumar M 

 

Thanks for your response.

We don't have any mapping.

The asset type column is custom string field with choices.

Can we try to do with client script on the table with script include to get the model category and set.

 

Will it works?

 

Thanks.

AnveshKumar M
Tera Sage

Hi @Community Alums 

 

You can try this, if you have only few type-> category mappings.

 

1. Create a Script Include like the one below.

var AssetCategoryCustomUtils = Class.create();
AssetCategoryCustomUtils.prototype = {
    initialize: function() {
    },

	getAssetCategory: function(ast_type){
		//You can add all your types and correspodning category sys_id from cmdb_model_category table in the below object
		var ast_type_category_mappings = {
			'laptop': '81feb9c137101000deeabfc8bcbe5dc4', //sys_id of computer category in cmdb_model_category
			'TV Monitor' : '81feb9c137101000deeabfc8bcbe5dc4' //sys_id of computer category in cmdb_model_category
		};
		var cat = ast_type_category_mappings[ast_type];
		if(gs.nil(cat)){
			return '';
		}else{
			return cat;
		}
	},

    type: 'AssetCategoryCustomUtils'
};

AnveshKumarM_0-1700469833220.png

 

2. Create a Before Insert/Update Business rule like the one below on cmdb_model table.

(function executeRule(current, previous /*null when async*/) {

	if(current.u_asset_type == ''){ //Change asset type field name as per your dictionary configuration
		return;
	}
	var cat = new AssetCategoryCustomUtils();
	current.cmdb_model_category = cat.getAssetCategory(current.u_asset_type); //Change asset type field name as per your dictionary 

})(current, previous);

AnveshKumarM_1-1700469944188.png

 

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

Thanks,
Anvesh