Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Fix script to update Bulk CIs

Balaji Ramanath
Kilo Contributor

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

-----------------------------------------------------------------------------------------

1 ACCEPTED SOLUTION

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

View solution in original post

5 REPLIES 5

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