- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2022 07:28 AM
Hi
I have a change request which is stuck in Assess state. The change has been approved and implemented, I need to implement the change.
Here is the background script I ran in DEV instance, the script changed all the changes to implement.
what is wrong with the script?
var gr= new GlideRecord('change_request');
gr.addEncodedQuery("CHG0000186");
gr.query();
while(gr.next()){
gr.setWorkflow(false); //prevent running business rule
gr.state='-1';//implement state
gr.update();
}
thank you
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2022 07:36 AM
I see a couple things here. Your Encoded Query just was a change number but should say some more along the lines of "number=CHG0000186". Because of this it is ignoring your Encoded Query and querying the entire table. Since you are also only updating one change I would do a if (gr.next()) instead of a while. Since you query is very simple I would not use encoded query. That is for when you have something vary complicated with may a bunch of or statement or date ranges. Try this as your code.
var gr= new GlideRecord('change_request');
gr.addQuery("number", "CHG0000186");
gr.query();
if(gr.next()){
gr.setWorkflow(false); //prevent running business rule
gr.state='-1';//implement state
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2022 07:33 AM - edited ‎12-07-2022 07:33 AM
The issue is with your encoded query. Try this
var chg = new GlideRecord('change_request');
chg.get('sys_id_of_record_to_update');
chg.setWorkflow(false); //prevent running business rule
chg.state = -1;
chg.update();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2022 07:36 AM
I see a couple things here. Your Encoded Query just was a change number but should say some more along the lines of "number=CHG0000186". Because of this it is ignoring your Encoded Query and querying the entire table. Since you are also only updating one change I would do a if (gr.next()) instead of a while. Since you query is very simple I would not use encoded query. That is for when you have something vary complicated with may a bunch of or statement or date ranges. Try this as your code.
var gr= new GlideRecord('change_request');
gr.addQuery("number", "CHG0000186");
gr.query();
if(gr.next()){
gr.setWorkflow(false); //prevent running business rule
gr.state='-1';//implement state
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2022 07:49 AM
Thank you, that worked