https://www.servicenowguru.com/scripting/execute-scheduled-jobs-script/


cheduled jobs are an extremely useful way to automate processes in Service-now.com and lift some of the administrative burden of the tool off of the shoulders of your Service-now administrators. It’s very easy to create a scheduled job or a scheduled import. Typically there’s no scripting or advanced configuration involved at all. Just set it up with a schedule and let it run! There are some situations where you might need to execute a scheduled job outside of its normal schedule. You can always open up the scheduled job entry and click the ‘Execute Now’ button, but there are also probably times where you’d really like to automate the process based on some trigger in a workflow or state change in some ticket or CI.

This article shows you how you can use script to execute an already-scheduled job on-demand. To do this, you simply mimic the behavior of the ‘Execute Now’ button by querying for the scheduled job you want to execute and firing off the job. Here’s the script…

You can modify the script below by adding your scheduled job name and querying the appropriate table for your scheduled job as shown here. This will not work if you simply query the ‘sysauto’ table. You must query one of the extensions below directly.

  • ‘scheduled_import_set’ (Scheduled Import Sets)

  • ‘sysauto_script’ (Scheduled Script Execution)

  • ‘sysauto_template’ (Scheduled Template Generation)

  • ‘sysauto_report’ (Scheduled Report)

//Execute a scheduled script job
var rec = new GlideRecord('sysauto_script');
rec.get('name', 'YOUR_JOB_NAME_HERE');
if (typeof SncTriggerSynchronizer != 'undefined')
   SncTriggerSynchronizer.executeNow(rec);
else
   Packages.com.snc.automation.TriggerSynchronizer.executeNow(rec);