- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 05:11 PM
Hey all, i need some asssistance creating a script to update model categories on some hardware models that have the incorrect model categories captured.
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
Solved! Go to Solution.
- Labels:
-
Enterprise Asset Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 09:07 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 09:29 PM
thanks
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 09:43 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader