Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Scheduled script for last working day of the month

Rodzula
Tera Contributor

Hi Guys

 

Would this script work for a condition based on the last working day of the month?  running monthly.

 

function isLastWorkingDay(gdt) {
var today = gdt.getDayOfWeekLocalTime();
var thisMonth = gdt.getMonthLocalTime();
switch (today) {
// Saturday and Sunday are NOT the last working day of the month

case 6:
case 7:
return false;
break;
// If it's a Friday, add 3 and see if the month changes.
case 5:
var nextMonday = gdt;
nextMonday.addDaysLocalTime(3);
var nextMondayMonth = nextMonday.getMonthLocalTime();
return (nextMondayMonth != thisMonth);
break;


}

}

var now = new GlideDateTime();
var lwd = isLastWorkingDay(now);
answer = lw

 

 

Also, see highlighted in yellow

find_real_file.png

1 ACCEPTED SOLUTION

var gdt1 = new GlideDateTime();

if(gdt1.getDayOfMonth() >= 11){

var gdt = new GlideDateTime();

gs.log('Rodz triggered script');


var today = gdt.getDayOfWeekLocalTime();
var thisMonth = gdt.getMonthLocalTime();

 

if(today == 5){

var nextMonday = gdt;
nextMonday.addDaysLocalTime(3);
var nextMondayMonth = nextMonday.getMonthLocalTime();


if(nextMondayMonth != thisMonth){

 

 

}

View solution in original post

6 REPLIES 6

var gdt1 = new GlideDateTime();

if(gdt1.getDayOfMonth() >= 11){

var gdt = new GlideDateTime();

gs.log('Rodz triggered script');


var today = gdt.getDayOfWeekLocalTime();
var thisMonth = gdt.getMonthLocalTime();

 

if(today == 5){

var nextMonday = gdt;
nextMonday.addDaysLocalTime(3);
var nextMondayMonth = nextMonday.getMonthLocalTime();


if(nextMondayMonth != thisMonth){

 

 

}

After some testing last week, this still hasn't worked

 

i changed a bit of the code to :

 

var gdt1 = new GlideDateTime();

if (gdt1.getDayOfMonth() >= 11) {
var now = new GlideDateTime();
var lwd = isLastWorkingDay(now);
gs.info('Log1');
answer = lwd;
gs.info("Log1 : "+answer);
answer;

}
function isLastWorkingDay(gdt) {

gs.log('Rodz triggered script');


var today = gdt.getDayOfWeekLocalTime();
var thisMonth = gdt.getMonthLocalTime();
gs.log("Today : "+today);
switch (today) {
// Saturday and Sunday are NOT the last working day of the month

case 6:
case 7:
gs.log("Log : 1");
return false;
// break;
// If it's a Friday, add 3 and see if the month changes.
case 5:
var nextMonday = gdt;
nextMonday.addDaysLocalTime(3);
var nextMondayMonth = nextMonday.getMonthLocalTime();
gs.log("Log : 2");
return (nextMondayMonth != thisMonth);
// break;
}

}

 

seems like these is making the condition false

find_real_file.png