How to run a schedule job B after 7 days of Scheduled Job A runs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2022 06:07 AM
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
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 05:37 AM
Hello Aman,
Where should we define this code in ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 08:46 AM - edited 08-21-2024 08:46 AM
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.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 10:09 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 09:24 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 10:45 AM
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
Thanks,
Narsing