How to run a schedule job B after 7 days of Scheduled Job A runs

Viswasri Ponaka
Tera Contributor

Hi,

I have a scheduled job B that needs to run after 7 days of a scheduled job A runs. 
for scheduled job A: we restricted it to run only on particular day of particular months. example : months:[3,5] , day:[1,20](had this in system property).
so whenever A runs after 7 days B should also run. how to achieve this?

 

thanks in advance

9 REPLIES 9

suvro
Mega Sage
Mega Sage

Hi Viswasri,

 

What are doing in these schedule jobs ? If you are updating some records, then create a date field in that table and populate that field with date time when schedule job A ran, and schedule job B should compare that field with current date and check whether 7 days have passed then only it should execute the required script and should run everyday

 

OR

You can use the same logic as A but increment 7 days like months:[3,5] , day:[8,27]

I need to trigger emails I cannot have another system property since this is an escalation

Aman Kumar S
Kilo Patron

Hey,

You can have your code written for the main scheduled job, and you can run your other schedule job from the main one itself by explicitly using below code:

function runChildJob{
    var schJob = new GlideRecord('sysauto_script');
    schJob.newRecord();
    schJob.name = "name of scheduled job";
    schJob.active = true;
    schJob.run_type = 'once';
    var ed = new GlideDateTime();
    ed.addDays(7);
    schJob.run_start = ed;
    //add more details which you want
    schJob.insert();
}
Best Regards
Aman Kumar

thanks a lot will try this