While loop is updating only one record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 04:22 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 04:32 AM
Hi,
Have you define the count variable?
Regards,
Sourabh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 04:33 AM
yes I defined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 04:35 AM
This line should not work...
gs.info("Count of records updated="+count);
Replace it with this and check... gs.info("Count of records updated="+gr.getRowCount());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 08:48 PM