- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2015 06:04 AM
I have a custom script that runs as a Scheduled Job. There are times that I would like to kick off that job on-demand from another script (or even a workflow). Is there an API to find the scheduled job and execute it?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2015 06:34 AM
Hello Joanne,
Please refer to this section in the documentation:
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2015 07:00 AM
Yeah I'm betting you're right. Its probably using all kinds of parameters from the full object. If you fed just sys_ID that function would have to do a lookup on the table first.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 07:53 AM
(function executeRule(current, previous /*null when async*/) {
// Create a record in sys_trigger (Scheduled Script Execution)
var trigger = new GlideRecord('sys_trigger');
trigger.initialize();
// Set the name of the scheduled job
trigger.name = 'My Custom Scheduled Job'; // Set the job name
// Set the type of job to "script"
trigger.job_context = 'RunScriptJob'; // Make sure this aligns with the Job ID field
// Set when to run the job (for example, tomorrow at 4 PM)
var nextActionTime = new GlideDateTime();
nextActionTime.setDisplayValue('2024-09-19 16:00:00'); // Set this to the date and time you want
trigger.next_action = nextActionTime;
// Define the script that should be executed
trigger.script = 'gs.info("This is a scheduled script job running at 4:00 PM.");'; // Set your custom script here
// Set the trigger type (Run Once)
trigger.trigger_type = '0'; // 0 = Run Once, 1 = Repeat
// Save the record to schedule the job
trigger.insert();
gs.info('Scheduled script job created.');
})(current, previous);