logo

NJP

Background Script or Fix Script updates only one record even in even after using next()

Import · May 06, 2020 · article

Hi Guys,

I was facing an issue where my following simple script was updating only one record at a time.

var gr = new GlideRecord('cmdb_ci_server');
gr.addEncodedQuery('install_status=16');
gr.query();
while(gr.next())

{
gr.operational_status= 110;
gr.update();

}


It got my head scratching for some time and after that I tried inserting my code in a self-invoking function and it worked brilliantly. Just to save time of you guys who might face this issue in future the code is here.

(function (){ 
var gr = new GlideRecord('cmdb_ci_server');
gr.addEncodedQuery('install_status=16');
gr.query();
while(gr.next()){
    gr.operational_status= 110;
    gr.update();
} }());

Please mark this article Helpful, if it helped you.

Cheers,

Hardit Singh

View original source

https://www.servicenow.com/community/developer-articles/background-script-or-fix-script-updates-only-one-record-even-in/ta-p/2320160