- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2024 11:26 PM
Hi All,
I am trying to write a script to update a list of specific CIs on the cmdb_ci_handheld_computing table whose support group field is currently empty but need to update it to 'Device Admin - Break Fix'. I below script runs but doesn't update the value for some reason. How to go about troubleshooting and understanding what is wrong with it ?
// Specify the list of Handheld Computing Devices CIs that need updating
var ciList = ['HandheldCI001', 'HandheldCI002', 'HandheldCI003'];
// Query for Handheld Computing Devices CIs that are missing the Support group field value
var ciGr = new GlideRecord('cmdb_ci_handheld_computing');
ciGr.addQuery('name', 'IN', ciList);
ciGr.addNullQuery('support_group'); // 'support_group' is the field name for Support group
ciGr.query();
// Loop through the results and update the Support group field
while (ciGr.next()) {
ciGr.support_group = 'Device Admin - Break Fix';
ciGr.update();
gs.info('Support group updated for ' + ciGr.name + ' to Device Admin - Break Fix');
}
gs.info('Fix script completed.');
Thank you,
Praveen
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2024 11:31 PM
The line
ciGr.support_group = 'Device Admin - Break Fix';
cannot work. Instead, you have to store the Sys ID of the group with the name "Device Admin - Break Fix"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2024 06:32 AM
Hi @praveenkshanmu ,
As mentioned by @Maik Skoddow yes you have to give sys_id in order to set the support group name as it is a reference field, and i suggest that create a sys property and store the group sys_id and call that property in your script as directly hardcoding is not best practice of servicenow,
// Specify the list of Handheld Computing Devices CIs that need updating
var ciList = ['HandheldCI001', 'HandheldCI002', 'HandheldCI003'];
// Query for Handheld Computing Devices CIs that are missing the Support group field value
var ciGr = new GlideRecord('cmdb_ci_handheld_computing');
ciGr.addQuery('name', 'IN', ciList);
ciGr.addNullQuery('support_group'); // 'support_group' is the field name for Support group
ciGr.query();
// Loop through the results and update the Support group field
while (ciGr.next()) {
gs.print('inside ');
ciGr.support_group = gs.getProperty('support.group.cmdb.ci'); //create a property and store the group value
ciGr.update();
gs.info('Support group updated for ' + ciGr.name + ' to Device Admin - Break Fix');
}
gs.info('Fix script completed.');
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2024 11:31 PM
The line
ciGr.support_group = 'Device Admin - Break Fix';
cannot work. Instead, you have to store the Sys ID of the group with the name "Device Admin - Break Fix"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2024 10:13 PM
Thank you Maik! That helped.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2024 06:32 AM
Hi @praveenkshanmu ,
As mentioned by @Maik Skoddow yes you have to give sys_id in order to set the support group name as it is a reference field, and i suggest that create a sys property and store the group sys_id and call that property in your script as directly hardcoding is not best practice of servicenow,
// Specify the list of Handheld Computing Devices CIs that need updating
var ciList = ['HandheldCI001', 'HandheldCI002', 'HandheldCI003'];
// Query for Handheld Computing Devices CIs that are missing the Support group field value
var ciGr = new GlideRecord('cmdb_ci_handheld_computing');
ciGr.addQuery('name', 'IN', ciList);
ciGr.addNullQuery('support_group'); // 'support_group' is the field name for Support group
ciGr.query();
// Loop through the results and update the Support group field
while (ciGr.next()) {
gs.print('inside ');
ciGr.support_group = gs.getProperty('support.group.cmdb.ci'); //create a property and store the group value
ciGr.update();
gs.info('Support group updated for ' + ciGr.name + ' to Device Admin - Break Fix');
}
gs.info('Fix script completed.');
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2024 10:14 PM
Thank you Swathi, for taking the time out to re-create the script for me. Your advice was helpful.