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

Hello Aman,

 

Where should we define this code in ?

Hi @namanroc 

You can add this function within your main scheduled job and call a the function as the last statement in your scheduled job.

Best Regards
Aman Kumar

Hi @Aman Kumar S - It looks like you're missing parenthesis before the function parameters, and I'm not sure I would recommend creating a copy of Job B each time you run Job A.

 

@Viswasri Ponaka - Assuming Job A and Job B will always run the same script (i.e., Job B’s script doesn’t change based on Job A), you can schedule Job B to run daily with a condition that checks if Job A ran 7 days ago. Scheduled job executions are logged in the transaction log [syslog_transaction] like type=scheduler^url=JOB: System Trigger-{NAME OF JOB A}. However, I prefer to avoid string match on a non-unique value, so I might consider leveraging Execution Tracker (Progress Worker), or even a custom field like "Last run time" on the Scheduled Job [sysauto_script] table.

Manoj R Zete
Tera Expert

Hi @Viswasri Ponaka 

Use below code 

function runChildJob() {
var schJob = new GlideRecord('sysauto_script');
schJob.initialize();
schJob.name = "Name of Scheduled Job";
schJob.active = true;
schJob.run_type = 'once';

var ed = new GlideDateTime();
ed.addDays(7);
schJob.run_start = ed;

schJob.script = "gs.log('This is the script that runs for Job B');";

schJob.insert();
}

runChildJob();


Regards,
Manoj

Narsing1
Mega Sage

You may do something like this

1. Before you begin, create an event called "job.b" under event registry

Job A

//All your Script related Scheduled Job A
var dt = new GlideDateTime();
dt.addDaysUTC(7);
//Actual script related to Job A
/* here
****/

//Finally, create an event called "job.b"
gs.eventQueueScheduled("job.b", "", "<parm1 if any>", "<parm2 if any>", dt);

 

Create a Script action like this and proceed with your Job B code

Narsing1_0-1724262248672.png

 

Thanks,

Narsing