While loop is updating only one record

Madhu5
Tera Contributor

Hi All,

I have to update multiple records in CMDB table.But whenever I execute the fix script,Only one record is getting updated.Below is my code

var gr = new GlideRecord("cmdb_ci");
gr.addEncodedQuery("sys_class_name=table^operational_status=7^install_status!=7");

gr.query();
gs.info("count="+gr.getRowCount());
while (gr.next()) {
gr.install_status = '7'; //retired
gr.hardware_status = 'retired';
gr.hardware_substatus = "missing";
gr.update();
//count++;
}
gs.info("Count of records updated="+count);

 

First info statement is giving me the count of 115,the last info stetement is giving a count of 1.Not sure what is wrong.Please help

15 REPLIES 15

If you are trying to update records of 'cmdb_ci_business_app' class then hardware_status and hardware_substatus fields are not there on that table. You must be getting run time exception for this.

 

Please share if you have added any custom fields on this table.

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande