- 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 07:34 PM
Hi,
Can you provide details on on which table this is done and what is the field type?
what script you started with?
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 08:19 PM
Thanks
Its on the cmdb_hardware_product_model tablle looking to update the field cmdb_model_category which is a glide list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 08:39 PM
Is this the correct approach to run a fix script;
var asset = new GlideRecord('cmdb_hardware_product_model');
var encodedStr = ' string'
asset.addQuery(encodedStr ); //Hardware Asset Models
asset.query();
while (asset.next()) {
asset.setValue = '1234568'; //Model Category = sys_id of 'Personal Computer'
asset.update();
}
- 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