Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Need help with a fix script to update the support group on a list of CIs

praveenkshanmu
Tera Contributor

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

2 ACCEPTED SOLUTIONS

Maik Skoddow
Tera Patron

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"

View solution in original post

swathisarang98
Giga Sage

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

View solution in original post

4 REPLIES 4

Maik Skoddow
Tera Patron

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"

Thank you Maik! That helped.

swathisarang98
Giga Sage

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

Thank you Swathi, for taking the time out to re-create the script for me. Your advice was helpful.