- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 07:08 PM
Hi,
I have a requirement to write a fix script to update bulk CI records and update the status to 'Retired'. kindly assist me on fix script for the same. I tried something here below which I would like to run in the background script as it is a bulk number of CI records. Thank you in advance
-----------------------------------------------------------------------------------------
updateRecords();
function updateRecords(){
var gr = new GlideRecord('cmdb_ci');
gr.addEncodedQuery('My Query Here');
gr.update.setlimit(10);//Set limit to test the logic on few records
gr.query();
while(gr.next()){
gr.setValue('status','6');
gr.setWorkflow(false);
gr.update();
}
}
-----------------------------------------------------------------------------------------
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 07:58 PM
Another way as mentioned in the following NOW Support article is to use .updateMultiple(). Shouldn't use this with .setLimit(). It may slow down the instance during execution.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0826303
var gr = new GlideRecord("cmdb_ci");
gr.addEncodedQuery('My Query here');
gr.setValue('install_status', 4);
gr.setWorkflow(false); // Bypass business rules and workflows
gr.autoSysFields(false); // Do not update sys_updated_by, sys_updated_on, sys_mod_count, sys_created_by, and sys_created_on
gr.updateMultiple();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 07:24 PM
it should be below and not what u wrote , there was a typo i presume , irrespective of that what r u struggling with ? any specific area ? how many actual records r u trying to update ?
updateRecords();
function updateRecords() {
var gr = new GlideRecord("cmdb_ci");
gr.addEncodedQuery("My Query Here");
gr.setlimit(10); //Set limit to test the logic on few records
gr.query();
while (gr.next()) {
gr.setValue("status", "6");
gr.setWorkflow(false);
gr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 07:50 PM
Ravi - thank you. We are trying to update the status of 100k+ CI records.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 07:45 PM
Hi Balaji,
"status" is a label. It's necessary to specify column name. The name of the column corresponding to label "Status" is "install_status". It's also of type Integer and not String.
Also, note that the script will only update records directly in the cmdb_ci table and not those in table that inherits the cmdb_ci table.
function updateRecords() {
var gr = new GlideRecord('cmdb_ci');
gr.addEncodedQuery('My Query Here');
gr.update.setlimit(10); //Set limit to test the logic on few records
gr.query();
while (gr.next()) {
gr.setValue('install_status', 6);
gr.setWorkflow(false);
gr.update();
}
}
updateRecords();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 07:51 PM
Noted with thanks Hitoshi. Yes, trying to update the records only on the cmdb_ci table.