How to trigger task before 1 Business day

Mohammed20
Tera Contributor
Hi,
 
I added the script below in timer activity which is working fine and creating task one day before business day in our dev instance but the same script is not working in test instance, is in the script anything missing?
 
please help on this. Thank you!
answer = 0;
var gdttime = new GlideDateTime();
gdttime.setDisplayValue(current.variables.new_start_date.getDisplayValue());
gs.log("time check: "+gdttime );
gdttime.addaddDays(-1);
var schedulebd = new GlideSchedule('af4477491bad5e10883f11f2b24bcbab');
while (!schedulebd.isInSchedule(gdttime)) {
gs.log("schedule check: "+schedulebd);
gdttime.addDays(-1);
}
//answer = gdttime.getNumericValue();
answer = gs.dateDiff(new GlideDateTime(), gdttime, true);
gs.log("task created one day before business days: "+answer);
8 REPLIES 8

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.