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 05:47 AM
table name is "cmdb_ci_business_app"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 06:49 AM
add same filter query in cmdb_ci table.
and check, how many records are coming.
Shakeel Shaik 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 05:15 AM
Hi,
1. I would suggest you to change GlideRecord variable name, avoid using gr, it may cause such issue.
2. If you want to check any exceptions then always use try-catch to see runtime exceptions.
Please try below script:
try{
var count=0;
var cmdbGR = new GlideRecord("cmdb_ci");
cmdbGR.addEncodedQuery("sys_class_name=table^operational_status=7^install_status!=7");
cmdbGR.query();
gs.info("count="+gr.getRowCount());
while (cmdbGR.next()) {
count++;
gs.info('Updating record : '+count);
cmdbGR.install_status = '7'; //retired
cmdbGR.hardware_status = 'retired';
cmdbGR.hardware_substatus = "missing";
cmdbGR.update();
gs.info('UPdated record successfuly: '+count);
}
gs.info("Count of records updated="+count);
}catch(e){
gs.info('Exception in my script : '+e);
}
Such detailed logs will help you to find issue quickly.
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 05:33 AM
No luck.Its still updating one record and doesn't give me any exception.Can w e use updatemultiple in this use case?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 06:00 AM
Are you getting other logs added in while loop?
Thanks
Anil Lande