- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2020 11:38 PM
Hello Team,
Can anyone help me on the below script. I have to create schedule a report for every month second Tuesday and second Wednesday but it's not working can anyone help me.
var result;
var gdt = '2019-12-10 00:00:19';
gs.print(gdt);
var day = gdt.getDayOfWeek();
var week = gdt.getDayOfMonthLocalTime();
result = true;
} else {
result = false;
}
gs.print(result);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2020 12:05 AM
Hi,
Try this code. here are the changes made and its working in bg script.
1. the date/time has to be converted to glidedatetime
2. getDate() returns complete date not days. so corrected that.
var dt = '2019-12-10 00:00:19';
var gdt = new GlideDateTime(dt);
gs.print(gdt);
var day = gdt.getDayOfWeek();
var days = gdt.getDayOfMonthLocalTime();
gs.print(day);
gs.print(days);
if (day == 2 && ((days > 7 && days <=14) || (days >21 && days <=28))) {
result = true;
} else {
result = false;
}
gs.print(result);
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2020 12:47 AM
As i see the result is false, which means it did not took 2020-04-07 as 2nd tuesday.
If it has taken, it would have return true. Kindly recheck.
Also, mark the comment as a correct answer and helpful if it helps.
Regards,
Asif
2020 ServiceNow Community MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2020 01:19 AM
Hello Jry,
The code is working fine. I just checked with 07 april and 14th april. For 7th April, it is returning false. but for 14th april, it is returning true.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2020 02:24 AM
Can you help me for 1st Monday/Tuesday/ Wednesday as well take example for this month 1st of April is Wednesday and 6th April is First Monday and 7th April is first Tuesday. then how to schedule reports for all this three days First Monday/Tuesday/ Wednesday.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2020 03:33 AM
Hi,
Try like this.
var dt = '2020-04-07 06:23:19';
var gdt = new GlideDateTime(dt);
gs.print(gdt);
var day = gdt.getDayOfWeek();
var days = gdt.getDayOfMonthLocalTime();
gs.print(day);
gs.print(days);
if ((day == 1 || day==2 || day==3) && ((days >=1 && days <=7))) {
result = true;
} else {
result = false;
}
gs.print(result);
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2020 12:29 AM
It shouldnt be too hard to make
(function(){
var gdt_tuesday = new GlideDateTime();
gdt_tuesday.setDayOfMonthUTC(1);
var today = new GlideDateTime();
while(gdt_tuesday.getDayOfWeekUTC() != 2){
//Loops until we have the first tuesday
gdt_tuesday.addDaysUTC(1);
}
//add 1 week to get the 2nd tuesday
gdt_tuesday.addDaysUTC(7);
gs.print(gdt_tuesday);
var result = gdt_tuesday.getDate() == today.getDate();
gs.print(result);
})();