- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2022 12:17 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 03:09 AM
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){
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2022 01:49 AM
Hi,
You should run this script daily as you will need to check for the last working day on the 28th, 29th, 30th, 31.
Adding an if condition to check the day of month will prevent this from running before the 28th.
For example;
var gdt1 = new GlideDateTime();
if(gdt1.getDayOfMonth() >= 28){
insert your script here
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 02:06 AM
Hi
i made some modifications on a script ,
expecting it to run on friday, but it didn't here is the code
var gdt1 = new GlideDateTime();
if(gdt1.getDayOfMonth() >= 11){
function isLastWorkingDay(gdt) {
gs.log('Rodz triggered script');
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 = lwd;
answer;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 02:33 AM
Hi,
You've passed gdt as a parameter in the function but you haven't declared it.
Put var gdt = new GlideDateTime(); outside of the function.
Also you need to call the function. So above the function put isLastWorkingDay(gdt);
Thanks
Jake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 02:52 AM
Hi
I'm still a bit confused as to how you want me to structure these