changing class name of records by using back group scripts

honey121
Kilo Contributor

Hi Team,

I am trying to write a back ground query where I would like to move all the CI records which are sitting in the base class (cmdb_ci) to

respective classes like Server , Network gear etc.   Unfortunately when the data load happened one of Service now team member mapped all the

CI records to the base class and not the respective classes .     As there are 1000's of records, it is not possible for me to manually change

the class of these records , so I wanted to try a back ground script and the update the classes accordingly .       Since I did not want any

undesirables changes at mass level , so I was experimenting with one record and please find the script below .    

The issue is the class name is changing to "label" instead of intended class name .       In this script the intended class is "Network gear"   but currently class name is showing as "label".   Can somebody help me as to how I can move the class names for set of records .     Please find the screen shot attached

var gr = new GlideRecord('cmdb_ci');

gr.addQuery( 'name' , 'AUBX04')

gr.query();

while(gr.next()) {

gr.sys_class_name.setValue('Network Gear');

gr.update();

gs.print(gr.getClassDisplayValue());

gs.print(gr.category);

}

find_real_file.png

1 REPLY 1

Jaspal Singh
Mega Patron
Mega Patron

Hi Anitha,


'


Could you pass in the table dictionary name. Such as for Network Gear it is network_gear.



var gr = new GlideRecord('cmdb_ci');


gr.addQuery( 'name' , 'AUBX04')


gr.query();



while(gr.next()) {




gr.sys_class_name.setValue('table_dictionary_name);   //For instance Network Gear = network_gear.


gr.update();


gs.print(gr.getClassDisplayValue());


gs.print(gr.category);



}