Script to remove model Categories from Hardware Model

eagle18
Tera Contributor

Hey all, i need some asssistance creating a script to update model categories on some hardware models that have the incorrect model categories  captured. 

find_real_file.png

Issue i am tryiing to resolve is most of our EUC devices have been captured as both Computer and Personal Computer Model categoy which is causing inconsistant issues with reporting and ci classes mapping. 

What i'm attemting to do is put togeather a script to remove the computer category from the Model but my scripting skills are curently still limited so unsure on the best approach to do this. 

Appreciate your help

1 ACCEPTED SOLUTION

like this

var sysId = ''; // give sys_id of personal computer category

var gr = new GlideRecord("cmdb_hardware_product_model");
gr.addEncodedQuery("cmdb_model_categoryLIKE" + sysId);
gr.query();
while(gr.next()) {

	var arr = gr.cmdb_model_category.toString().split(',');
	var index = arr.indexOf(sysId);
	if (index > -1) {
		arr.splice(index, 1); // 2nd parameter means remove one item only
	}

	gr.cmdb_model_category = arr.toString();
	gr.setWorkflow(false);
	gr.update();
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

thanks @Ankur Bawiskar 

Does it matter that some Models are ordered differenty

  • Computer, Personal Computer
  • Personal Computer, Computer

Will the split only remove computer category even though the ordering is different?

Hi,

ordering will have no impact on removal

if you remove 1 category only 1 will be remaining and it won't matter.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader