Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Fix Script that is supposed to loop and update 3 records is only updating 1 record

Adam Johnson2
Tera Contributor

Hey Everyone, I am trying to create a fix script that will update the category field from operational to strategic.
I have built the below query and I build my filter on the demand table as the encoded query.

var gr = new GlideRecord('dmn_demand');
gr.addEncodedQuery('sys_class_name=dmn_demand^numberSTARTSWITHDMND0002494^ORnumberSTARTSWITHDMND0001775^ORnumberSTARTSWITHDMND0004052');
gr.query();

while (gr.next()) {
gr.setValue('category', 'strategic'); // Sets the Type Field
gr.update();
}

When I run this though it's only updating 1 record.
Does anyone know why this would not loop through and update the 3 records?

Here's a screenshot which was updated, which shows that only DMND0001775 had its category updated.
Note: I tried changing my encoded query to look at IS instead of contains and that didn't change the result.

 

AdamJohnson2_0-1697823664484.png

 

2 REPLIES 2

Alka_Chaudhary
Mega Sage
Mega Sage

Hello @Adam Johnson2 ,

Your script looks correct. Check the table name and add encoded query using the breadcrumb can solve your issue.

Please Mark my answer Helpful & Accepted if I have answered your question.

Thanks,

Alka

Sandeep Rajput
Tera Patron
Tera Patron

@Adam Johnson2 The only possible explanation here is either the Demand DMND0002494 and DMND0004052 don't exist in the dmn_demand table or their class is different from dmn_demand.

 

Hope this helps.