Skip to content

Commit 1eee905

Browse files
authored
Feature/run scheduled job via script (#1989)
* Create run-scheduled-job.js Adding the code * Create README.md Added readme file * Update README.md Added instructions to readme
1 parent f91605c commit 1eee905

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A script to run an existing Scheduled Job programmatically. Can be used as Background script, in a Script Include or anywhere a server side script is available.
2+
Replace `sys_id` with the Sys ID of the Scheduled Job to be run.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Generic/parent scheduled job table = sysauto
2+
var grScheduledJob = new GlideRecord("sysauto");
3+
if (grScheduledJob.get(sys_id)) {
4+
// In order to run the job successfully, we need the more specific
5+
// child table name of the scheduled job (eg. sysauto_script)
6+
var classname = grScheduledJob.getValue('sys_class_name');
7+
var scheduledJob = new GlideRecord(classname);
8+
if (scheduledJob.get(sys_id))
9+
gs.executeNow(scheduledJob);
10+
}

0 commit comments

Comments
 (0)