Execute a scheduled job after an Import is processed

GChanner
Tera Guru

I am trying to trigger to execute a scheduled job to run immediately. Upon completion the script should call and execute the scheduled job but its not working.

Can anyone assist me in accomplishing this, below is the script I am using

 

(function runTransformScript(source, map, log, target) {
// Define the name of the scheduled job
var scheduledJobName = 'Scheduled Execution of Dell Asset Import Automation';

// Query the sysauto_script table for the scheduled job
var scheduledJob = new GlideRecord('sysauto_script');
scheduledJob.addQuery('name', scheduledJobName); // Match by job name
scheduledJob.query();

if (scheduledJob.next()) {
// Use GlideScheduleWorker to execute the job immediately
var jobId = scheduledJob.sys_id.toString();
gs.print('Found scheduled job. Executing job ID: ' + jobId);

// Execute the job
var worker = new GlideScheduleWorker(jobId);
worker.start();
} else {
gs.print('Scheduled job not found: ' + scheduledJobName);
}
})(source, map, log, target);

 

2 REPLIES 2

Robbie
Kilo Patron
Kilo Patron

Hi @GChanner,

 

Are you implementing this as an onComplete 'Transform Script'?

If not, this is exactly what these are for...

For sample code as to how to trigger the Scheduled Job, see below:

 

var schedJobGR = new GlideRecord('sysauto_script');
schedJobGR.addQuery('name','Test Scheduled Job'); // The name of the scheduled job
schedJobGR.query();
if(schedJobGR.next()){
   SncTriggerSynchronizer.executeNow(schedJobGR); // use syntax for global scope
   //gs.executeNow(schedJobGR); // use this syntax for scoped app
}

 

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.




Thanks, Robbie

GChanner
Tera Guru

Hi Robbie,

 

Thanks for jumping in. I am doing this 'onComplete' in the transform script.

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
 
var schedJobGR = new GlideRecord('sysauto_script');
schedJobGR.addQuery('name', 'Scheduled Execution of Dell Asset Import Automation'); // The name of the scheduled job
schedJobGR.query();
if(schedJobGR.next()){
   SncTriggerSynchronizer.executeNow(schedJobGR); // use syntax for global scope
   //gs.executeNow(schedJobGR); // use this syntax for scoped app
}
})(source, map, log, target);

 

I tested it in the background script and got the following:

Evaluator: com.glide.script.RhinoEcmaError: "source" is not defined.
   script : Line(13) column(0)
     10:    //gs.executeNow(schedJobGR); // use this syntax for scoped app
     11: }
     12: 
==>  13: })(source, map, log, target);

Thanks

Garfield