How to update the schedule job to run only on saturday and sunday

BalaLalitha Gun
Tera Contributor

Hello Team,

 

We have a Workday integration scheduled job that is running daily at 12:30 PM IST as per OOB.

 

But as per the requirement, i have created another scheduled job, same as the existing but the new job should run only on Saturday and Sunday. 

The existing job should run from Monday to Friday.

 

I have made the changes accordingly. But the problem here is both jobs are running daily.

 

How should i seperate the jobs like existing one should run on weekdays and the new job should run on weekends?

function notAlreadyrunning() {
    //Only run the script when it's not already running
    var jobName = hrIntegrations.WORKDAY_JOB_NAME;
    var gr = new GlideRecord(hrIntegrations.JOB_TRACKER_TABLE);
    gr.addNotNullQuery("job_started_at");
    gr.addNullQuery("job_ended_at");
    gr.addQuery("job_name", jobName);
    gr.query();
    var result = true;
    if (gr.next()) {
        gs.info(jobName + "is already running", hrIntegrations.HR_INT_SCHEDULER_LOG);
        result = false;
    }
    return result;
}


(function executeScheduleJob() {
    var currentDate = new GlideDateTime();
    var dayOfWeek = currentDate.getDayOfWeekUTC(); // Returns 1 (Monday) through 7 (Sunday)

    // Check if the current day is a weekend(sat n sunday)
    if ((dayOfWeek == 6 || dayOfWeek == 7) && (notAlreadyrunning())) {
        gs.log("Checking week day : " + dayOfWeek);
        gs.log("Scheduled Job executed on a weekend");
        return true;

    } else {
        gs.log("Scheduled Job skipped because it's a weekday");
        return false;
    }
})();

BalaLalithaGun_0-1725953791068.png

 

1 REPLY 1

BalaLalitha Gun
Tera Contributor

Any update on this please?