Facing issue with Schedule and TimeZone

gana2
Tera Contributor

Hello Everyone, I'm facing an issue with the Schedule and Timezone.

Requirement - Need to send additional Approval if the change window is in Working Hours.

Note - The instance and the user who is creating the change are in Australia/Melbourne Timezone.

Schedule(cmn_schedule) also in Australia/Melbourne.

 

1. I have created an Australia/Melbourne schedule and schedule entry for Monday to Friday 6:00:00 to 22:00:00 

 

Screenshot (219).png

 

Screenshot (220).png

 

2. Then Created a change request which change the planned start date is on Monday (2024-01-08 16:11:40).

Screenshot (221).png

 

 

 

 

3. Now from the BG Script I'm checking planned start date is on schedule or not but it is showing it is not on schedule.

below is the script 

-------------------------------------------------------- Script -------------------------------------------------------------------------

var gr = new GlideRecord('change_request');
gr.query('sys_id', 'c83c5e5347c12200e0ef563dbb9a7190');
gr.query();

if (gr.next()) {
var startDateTime = new GlideDateTime(gr.start_date);
gs.print('GMT Start time -'+startDateTime);
var tz = Packages.java.util.TimeZone.getTimeZone('Australia/Melbourne');
startDateTime.setTZ(tz);
var timeZoneOffSet = startDateTime.getTZOffset();
startDateTime.setNumericValue(startDateTime.getNumericValue() + timeZoneOffSet);

gs.print('Australia/Melbourne Start time - '+startDateTime);
    var g = new GlideRecord('cmn_schedule');
    g.addQuery('name', '8-5 weekdays');
    g.query();

    if (g.next()) {
        var sched = new GlideSchedule(g.sys_id);

        // Check if either start or end date is in the schedule
        if (sched.isInSchedule(startDateTime)) {
            gs.print("In Schedule Need Approval");
        } else {

             gs.print("Not In Schedule No Need Approval");

        }
    }
}

 

-------------------------------------------------------- Script -------------------------------------------------------------------------

out put 

*** Script: GMT Start time -2024-01-08 05:11:40
*** Script: Australia/Melbourne Start time - 2024-01-08 16:11:40
*** Script: Not In Schedule No Need Approval

 

And also if I'm trying to print getDayofWeek if date is on Sunday it's giving 1 some times and 7 some times 

Screenshot (222).png

 

 

 

Could you please someone help how to get this requirement 

 

Thanks in advance 

Ganasekhar

 

0 REPLIES 0