Test Scheduled Jobs(and Fix Scripts) in the Script Debugger
Hi,
I love the ServiceNow Script Debugger! It has made testing in ServiceNow much easier.
One challenge I had though was that scheduled jobs run in the background, and so they cannot be run in the script debugger.
Fortunately, there is a way to run your scheduled jobs in the foreground so that you can step through them in the script debugger.
All you need to do is add a UI Action with the following code to the Scheduled Script Execution (sysauto_script) table. I've attached the UI Action I use. It's called Test Script, because ... well you can imagine why.
try{
var evaluator = new GlideScopedEvaluator();
evaluator.evaluateScript(current, 'script');
action.setRedirectURL(current);
}
catch(e){
gs.addInfoMessage(e);
}
That's it.
Once you have this UI Action in place, you'll be able to run test your Scheduled Job scripts in the script debugger.
AND ... a couple notes.
- If you use this "functionality" to test a script, remember that you'll be running your script in the foreground, so limit the number of records you are processing and so that you don't end up sitting there waiting for your script to time out!
- You can also use this method to test Fix Scripts in the Script Debugger.
- Since you can call Script Includes from Scheduled Jobs, this gives you a way to easily test Script Includes.
I hope other people find this helpful. I know that being able to test Scheduled Jobs and Fix Scripts in the script debugger has saved me a lot of time.
Let me know if you have questions.
Thanks,
Cody
https://www.servicenow.com/community/now-platform-articles/test-scheduled-jobs-and-fix-scripts-in-the-script-debugger/ta-p/2321945