changing class name of records by using back group scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2017 03:29 AM
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);
}
- Labels:
-
Enterprise Asset Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2017 10:31 AM
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);
}