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

ersureshbe
Giga Sage
Giga Sage

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,

Regards,
Suresh.

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.

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

Regards,
Suresh.

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,

Regards,
Suresh.

Shakeel Shaik
Giga Sage
Giga Sage

Hi,

 

sys_class_name=table

 

what is the table name here??

Thanks,
Shakeel Shaik 🙂