How to remove value from field by Background Script

Kasia5
Tera Contributor

Hi All,

 

I need to remove value from field in many records and I want to do this by Background Script.

Field from which I need to remove value is 'operational_status' in Servers:

Kasia5_0-1691135745195.png

The issue is that when I open the record then in every record table in different so I think I need to use cmdb_ci table and I war trying by below script:

var test = new GlideRecord("cmdb_ci");
test.addEncodedQuery('operational_status=1^correlation_idLIKESYS_');          //When operational status is operational and Source ID contains SYS_
test.query();

if(test.next()){
test.setValue("operational_status", "");
test.setWorkflow(false); //Do not run business rules
test.update();
}

 

but it showed that it works only for one record...

How can I resolve this?

 

Thanks in advance for help!

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

var test = new GlideRecord("cmdb_ci");
test.addEncodedQuery('operational_status=1^correlation_idLIKESYS_');          //When operational status is operational and Source ID contains SYS_
test.query();

if(test.next()){ // you need to use while here instead of if to loop multiple records
test.setValue("operational_status", "");
test.setWorkflow(false); //Do not run business rules
test.update();
}

Regards
Harish

View solution in original post

3 REPLIES 3

Harish KM
Kilo Patron
Kilo Patron

var test = new GlideRecord("cmdb_ci");
test.addEncodedQuery('operational_status=1^correlation_idLIKESYS_');          //When operational status is operational and Source ID contains SYS_
test.query();

if(test.next()){ // you need to use while here instead of if to loop multiple records
test.setValue("operational_status", "");
test.setWorkflow(false); //Do not run business rules
test.update();
}

Regards
Harish

Kasia5
Tera Contributor

It works! Thank you! 🙂

thanks so much