- 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-19-2020 11:43 PM
Hey Jry,
Please refer to this Community Post: https://community.servicenow.com/community?id=community_question&sys_id=8cee83a1dbdcdbc01dcaf3231f96...
If it helps then please mark my answer Correct and Helpful.
Thanks and Regards:
Utpal Dutta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2020 12:15 AM
It's returning false.

- 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:27 AM
I have made chnages to date and time
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);
I have got this
*** Script: 2020-04-07 06:23:19
*** Script: 2
*** Script: 7
*** Script: false
can you help me on this because as we can see that 2020-04-07 is first Tuesday of this month and 2020-04-14 is second tuesday but it's taking 2020-04-07 as second tuesday of the month