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:42 AM
Hi,
I can see the error in yellow highlighted. Class name should be proper name example cmdb_ci_server.
gr.addEncodedQuery("sys_class_name=table^operational_status=7^install_status!=7");
For Example, You replace with
gr.addEncodedQuery("sys_class_name=cmdb_ci_server^operational_status=7^install_status!=7");
Regards,
Suresh,
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 04:49 AM
I have given that correctly in the instance. All the syntax is working fine and the script is executed without any errors and exceptions. But its only updating one record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 04:54 AM
I wondering, how it will execute? I'm sure there is no class name as table. I'm sure you have an error in mentioned line above.
Regards,
Suresh
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 05:51 AM
Hi,
Can you replace your line like below and execute.
gr.addEncodedQuery("sys_class_name=cmdb_ci_business_app^operational_status=7^install_status!=7");
Regards,
Suresh,
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 04:48 AM
Hi,
sys_class_name=table
what is the table name here??
Shakeel Shaik 🙂