2nd Business day of the month

Khanna Ji
Tera Guru

Hi Team,

How can I schedule a job to run only on the 2nd working day of the month? For example in the month of January of this year, 4th is the second working day, so job should run only on 4th. Only once in a month that too on a second business day.

 

 

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Khanna,

To exclude holiday, use Schedule.

  1. Create a new Schedule (from Navigator, go to System Scheduler > Schedules > Schedules)
    I've create a schedule named "Weekdays excluding Holiday".
    Add "U.S. Holidays" as a Child Schedule.
    find_real_file.png
  2. Create Schedule Entries to the schedule
    find_real_file.png
  3. Set Condition on Scheduled Job
    Run: Daily
    Condition:
    function checkIfSecondDay() {
        var grSchedule = new GlideRecord('cmn_schedule');
        if (grSchedule.get('name', 'Weekdays excluding Holiday')) {
            var sched = new GlideSchedule(grSchedule.sys_id);
    
            var gdt = new GlideDateTime();
            gdt.setValue(gs.beginningOfThisMonth());
    
            var days = 1;
            var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
            var secondDay = sched.add(gdt, dur);
    
            var today = new GlideDateTime();
            today.setDisplayValue('2022-01-05 12:00:00');
    
            return (today.getDayOfMonthLocalTime() == secondDay.getDayOfMonthLocalTime());
        }
        return false;
    }
    
    checkIfSecondDay();​

    find_real_file.png

View solution in original post

6 REPLIES 6

As per the screenshot. Job will run only once on 3rd day of the month. And if the script conditions are not matching when it ran then it will run next month. This doesn't work.

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Khanna,

To exclude holiday, use Schedule.

  1. Create a new Schedule (from Navigator, go to System Scheduler > Schedules > Schedules)
    I've create a schedule named "Weekdays excluding Holiday".
    Add "U.S. Holidays" as a Child Schedule.
    find_real_file.png
  2. Create Schedule Entries to the schedule
    find_real_file.png
  3. Set Condition on Scheduled Job
    Run: Daily
    Condition:
    function checkIfSecondDay() {
        var grSchedule = new GlideRecord('cmn_schedule');
        if (grSchedule.get('name', 'Weekdays excluding Holiday')) {
            var sched = new GlideSchedule(grSchedule.sys_id);
    
            var gdt = new GlideDateTime();
            gdt.setValue(gs.beginningOfThisMonth());
    
            var days = 1;
            var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
            var secondDay = sched.add(gdt, dur);
    
            var today = new GlideDateTime();
            today.setDisplayValue('2022-01-05 12:00:00');
    
            return (today.getDayOfMonthLocalTime() == secondDay.getDayOfMonthLocalTime());
        }
        return false;
    }
    
    checkIfSecondDay();​

    find_real_file.png