Run Scheduled job from script

Hello ServiceNow Geeks,

In this article, I will cover a very important and interesting topic in ServiceNow. It is about on demand execution of scheduled job from script in workflow run script activity or any business rule, or any other scripting flow.

As you are aware Scheduled Job helps in automating a repetitive task, which in return removes the dependency of manual intervention to run script in ServiceNow. Scheduled job can be defined to run on a specific day, time, week or even monthly basis.

Feature of on-demand execution of scheduled job can be achieved using ‘Execute Now’ button in scheduled job. But to call a scheduled job on undefined timelines and even on demand basis can be done by calling it from script acitivity.

/*Execute scheduled data import having sys_id 'a1e28416db5998142104d7b2f39619b6'

var exportGr = new GlideRecord('scheduled_import_set');
exportGr.addQuery('sys_id', 'a1e28416db5998142104d7b2f39619b6');
//User gs object to execute scheduled job for scoped application
//Use SncTriggerSynchronizer object to execute script in global scope

This script can be used to run scheduled job from script in any of the following-

  • Run script activity in workflow
  • Business rule
  • Script Include

Point to remember is, there are separate tables defined in ServiceNow for every type of Scheduled jobs. Below is the information about those tables-

Scheduled Job Table LabelDictionary Name
Scheduled Import Sets (Above Example)scheduled_import_set
Scheduled Reportsysauto_report
Scheduled Script Executionsysauto_script
Scheduled Template Generationsysauto_template

I hope the above script will help you to run ServiceNow scheduled job from script. Please do comment and share your views about this post. I will continue to add content on it as it learn new things.

Leave a Reply

Your email address will not be published. Required fields are marked *