- 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: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();