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

Anand Shukla
Mega Guru

 

Hi,

Use the below code in condition and try i hope it will work.

var today = new GlideDateTime();
var dayOfWeek = today.getDayOfWeek();

if(dayOfWeek == 2 ){

return true;

}

 

Mark it helpful || Correct

 

Thanks and regards

Anand

use this scheduled job as periodically.

dmathur09
Kilo Sage
Kilo Sage

Hi,

You can change the Run field as Monthly and keep the Day as 2.

find_real_file.png

You can check the conditional checkbox as true and write the below mentioned script.

//Return 'true' to run the job
var answer = false;

//Get the day of week. 1=Monday, 7=Sunday
var now = new GlideDateTime();

//Run only on weekdays
if(now.getDayOfWeek() < 6){
   answer = true;
}
answer;

Regards,

Deepankar Mathur

The above script runs 4 times every month, suppose we want to run only on the 2nd Business day in the month and only once and not after that?