Fix Script that is supposed to loop and update 3 records is only updating 1 record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2023 10:41 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2023 10:50 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2023 10:53 AM
@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.