
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 01:39 AM
Good Morning,
Please can someone advise... i need a background script to force two CHG records to the state Implement. We have discovered a fault within the change workflow and whilst we get that sorted.. we need to manually force a couple of changes to "implement" so we can proceed with them.
Advise/the script we need to run... would be much appreciated.
As you can see.. i am unable to change the state from the list view (or the form view)
thanks again!
Solved! Go to Solution.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 01:56 AM
Hi,
As per OOB normal change state model , change can we move from authorize to schedule/cancel states only. .
See 'ChangeRequestStateModel_normal' script include.
So, you need use setWorkflow to false before running the script in backgroud or else business rule will stop doing that. Try below script:
var gr= new GlideRecord('change_request');
gr.addEncodedQuery("numberINCHG0030712,CHG0030714");
gr.query();
while(gr.next()){
gr.setWorkflow(false); //prevent running business rule
gr.state='-1';//implement state
gr.update();
}
Hope this helps!
If I have answered your question, please mark my response as correct and/or helpful.
Thanks,
Suseela P.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 01:48 AM
var changeGR=new GlideRecord('change_request');
changeGR.addEncodedQuery('number=CHG0040007^ORnumber=CHG0040006'); // replace with correct change number
changeGR.query();
while(changeGR.next()){
changeGR.state='3'; // replace state value here
changeGR.update();
}
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 02:02 AM
Just add changeGR.setWorkflow(false); in above script before setting value to state
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 01:52 AM
try this script in one time scheduled job
Ensure you give valid change numbers, valid choice values when you execute
updateRecords();
function updateRecords(){
try{
var numbers = ['CHG001', 'CHG002']; // give the change numbers here
var rec = new GlideRecord('change_request');
rec.addQuery('number', 'IN', numbers);
rec.query();
while(rec.next()){
rec.state = -1; // give valid choice value here
rec.setWorkflow(false); // to avoid triggering any BR
rec.update();
}
}
catch(ex){
gs.info('Exception is:' + ex)
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 01:56 AM
Hi,
As per OOB normal change state model , change can we move from authorize to schedule/cancel states only. .
See 'ChangeRequestStateModel_normal' script include.
So, you need use setWorkflow to false before running the script in backgroud or else business rule will stop doing that. Try below script:
var gr= new GlideRecord('change_request');
gr.addEncodedQuery("numberINCHG0030712,CHG0030714");
gr.query();
while(gr.next()){
gr.setWorkflow(false); //prevent running business rule
gr.state='-1';//implement state
gr.update();
}
Hope this helps!
If I have answered your question, please mark my response as correct and/or helpful.
Thanks,
Suseela P.