Issue: ATF Schedule Condition Not Triggering with Script Include (Odd/Even Week Logic)

pavi12
Tera Contributor

I was trying to run an ATF Schedule (sys_atf_schedule) based on odd-week Mondays (1st, 3rd, 5th) using a Script Include.

 

I created a Script Include to identify odd weekday occurrences:

 

    isOddWeekday: function(targetDay) {
        gs.log("inside function");
        var now = new GlideDateTime();
        // Check if today is the required weekday
        if (now.getDayOfWeekLocalTime() != targetDay) {
            return -1;
        }
        // First day of month
        var firstOfMonth = new GlideDateTime(now);
        firstOfMonth.setDayOfMonthLocalTime(1);

        // Find first occurrence of that weekday
        var probe = new GlideDateTime(firstOfMonth);
        while (probe.getDayOfWeekLocalTime() != targetDay) {
            probe.addDaysLocalTime(1);
        }

        var firstDay = new GlideDateTime(probe);

        // 1st, 3rd, 5th occurrence
        var occ1 = new GlideDateTime(firstDay);

        var occ3 = new GlideDateTime(firstDay);
        occ3.addWeeksLocalTime(2);

        var occ5 = new GlideDateTime(firstDay);
        occ5.addWeeksLocalTime(4);

        var today = now.getLocalDate().getValue();

        if (
            today == occ1.getLocalDate().getValue() ||
            today == occ3.getLocalDate().getValue() ||
            (occ5.getMonthLocalTime() == now.getMonthLocalTime() &&
                today == occ5.getLocalDate().getValue())
        ) {
            gs.log("Inside pass true")
            return 1;
        }
        return -1;
    },
 
This works correctly when tested independently.
In ATF Schedule condition, I used:

 

 
var result = oldWeekMonday();

if (result == true) {
answer = true;
} else {
answer = false;
}



function oldWeekMonday() {
var day = current.run_dayofweek;
return new ScheduleUtils().isOddWeekday(day);
}

  • Schedule does not trigger
  • But if I use: answer = true; it works fine
 

Could anyone please advise on this how to approach ?

 

Thanks,

Pavithra

0 REPLIES 0