- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2016 09:28 PM
Hi Kiki,
Out of the box there's a script include BillingReportUtil which has a function to create a scheduled job on the fly. It's similar to what Chuck shared but I'm adding it just for reference in case it helps and also because it's a production "tested" version i guess :
the function is called from a business rule on the following way:
var billingUtil = new BillingReportUtil();
billingUtil.createScheduledJob(current, 'sysauto_script', 'Amazon', 'AwsBillingReportUtil');
The method createScheduledJob within the BillingReportUtil script include is the following:
// Used for report schedule business rule to generate/update scheduler
createScheduledJob : function(currentGr, schedulerTable, provider, scriptName) {
var scheduleJobId = currentGr.scheduler;
var gr = new GlideRecord(schedulerTable);
var name = provider + ' Billing Report Scheduler Job for : ' + currentGr.name;
if (currentGr.scheduler.nil()){
gr.name = name;
gr.active = true;
var script = 'var billingUtil = new BillingReportUtil(); \n';
script = script + 'if(!billingUtil.isBillingWorkflowExecuting(\''+currentGr.sys_id+'\'));\n';
script = script + ' billingUtil.runThisJob(\''+currentGr.sys_id+'\');';
script = script.replace('BillingReportUtil', scriptName);
gr.setValue('script',script);
var sysId = gr.insert();
currentGr.setValue('scheduler',sysId);
if(provider == 'Azure')
currentGr.update();
}
else{
gr.get(currentGr.scheduler);
gr.name = name;
gr.update();
}
}
Thanks,
Berny