Friday, 30 November 2018

Script to Trigger scheduled_import_set / sysauto_script / sysauto_template / sysauto_report from Server Side Script in ServiceNow

Following code you can have to trigger schedule job from business rule.

var schImp_GR = new GlideRecord('sysauto');
schImp_GR.addQuery('name','<name>');
schImp_GR.query();
if(schImp_GR.next()){
SncTriggerSynchronizer.executeNow(schImp_GR); // this is for global scope
}

Or

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);


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)

No comments:

Post a comment