Mohammed20
Tera Contributor

Hi  Olan,

 

Thanks for your reply!

I had correct the error, yes the variable getting the proper time as checked in logs through both the way getValue and setValue instead of getDisplayValue() and setDisplayValue().

 

If the day is business day then script is only generating a task one day before and if it is not an business days then generating two days before and does not calculating the properly, for example i have excluded 1st November in cmn_schedule and chose the date in variable for 4th November Monday but the script is not generating a task today which will be create tomorrow 1st November as you can see below.

 

var answer = 0;
var gdttime = new GlideDateTime();
gdttime.setValue("2024-11-04 12:30:00");
gs.info("time check: "+gdttime );
gdttime.addDays(-1);
gs.info("time check: "+gdttime);
var schedulebd = new GlideSchedule('af4477491bad5e10883f11f2b24bcbab');
while (!schedulebd.isInSchedule(gdttime)) {
gs.info("schedule check: "+schedulebd);
gdttime.addDays(-1);
gs.info("time check1: "+gdttime);
}
answer = gs.dateDiff(new GlideDateTime(), gdttime, true);
gs.info("task created one day before business days: "+answer);
gs.info('task created day: ' +gdttime);

 

 

*** Script: time check: 2024-11-04 12:30:00
*** Script: time check: 2024-11-03 12:30:00
*** Script: schedule check: com.glide.schedules.Schedule@51a89dc3
*** Script: time check1: 2024-11-02 11:30:00
*** Script: schedule check: com.glide.schedules.Schedule@51a89dc3
*** Script: time check1: 2024-11-01 11:30:00
*** Script: task created one day before business days: 63039
*** Script: selected day: 2024-11-01 11:30:00
 

Well, the script seems fine, as far as I can see.

I cannot validate if the calculation on your schedule is correct,

because I don't know what your schedule looks like.

Mohammed20
Tera Contributor

Hi OlaN,

Thanks! Everything working fine now, the issue was in cmn scheduled, The only thing observed was the script subtracting one hour as well for example below the start time of  2024-11-04 12:30:00 and the task generating time is 2024-11-01 11:30:00. 

Is this the expected or something missing in the script.

*** Script: time check: 2024-11-04 12:30:00
*** Script: time check: 2024-11-03 12:30:00
*** Script: schedule check: com.glide.schedules.Schedule@51a89dc3
*** Script: time check1: 2024-11-02 11:30:00
*** Script: schedule check: com.glide.schedules.Schedule@51a89dc3
*** Script: time check1: 2024-11-01 11:30:00
*** Script: task created one day before business days: 63039
*** Script: selected day: 2024-11-01 11:30:00

 

I would say that the difference is because of timezone and/or daylight savings differences.

Again, there is a difference whether you are using the displayvalue or the value, where the displayvalue takes account into difference between the users timezone and daylight savings, compared to the value stored in the database.

Mohammed20
Tera Contributor

The system time is in GMT and i am also adding the time in GMT on the variable.

We have tried both displayvalue or the value and same result and now using only getValue and setValue.

We will test on Monday because DST will start from 2nd November mid night.