- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2020 01:45 PM
I am hoping that Scheduled job can run 15 days before the 1st of each month. As months have a varying number of days, the job should not always run on the 15th of the month.
This scheduled job currently does not run 15 days before the first of the current month as the story requires. Instead, it currently runs on the 3rd and the 15th of each month, with the following results:
- Sends a monthly report reminder email notification too many days in advance of the first of the month
- Makes the monthly report reminder email notification sent less than 15 days for reports due February 1
- Makes the monthly report reminder email notification sent more than 15 days in advance when the current month has 31 days in it instead of 30
Does anyone know what I do wrong?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2020 09:45 AM
I have found a solution to fix it.
var gdt = new GlideDateTime();
//gdt.getDaysInMonthUTC() get total days in current month. It can be 30, 31, or 28.
var result = (gdt.getDaysInMonthUTC() + 1) - 15; //Subtract 15 days from total days of current month plus 1 to find a correct day to send out notification.
/*
Suppose this month total days is 31. Then subtract by 15 and add by 1 which should be day 17 of this month to send out notification. Then in IF statement, gdt.getDayofMonth() get the today day suppose it is 17 and the result is 17 that are matched, it will send out notification.
*/
if(gdt.getDayOfMonth() == result){//current day must match the calculated result of day that should send out notification
var gr2 = new GlideRecord('sn_customerservice_test');
gr2.addEncodedQuery('query');
gr2.query();
while (gr2.next()) {
//send out notifications
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2020 09:45 AM
I have found a solution to fix it.
var gdt = new GlideDateTime();
//gdt.getDaysInMonthUTC() get total days in current month. It can be 30, 31, or 28.
var result = (gdt.getDaysInMonthUTC() + 1) - 15; //Subtract 15 days from total days of current month plus 1 to find a correct day to send out notification.
/*
Suppose this month total days is 31. Then subtract by 15 and add by 1 which should be day 17 of this month to send out notification. Then in IF statement, gdt.getDayofMonth() get the today day suppose it is 17 and the result is 17 that are matched, it will send out notification.
*/
if(gdt.getDayOfMonth() == result){//current day must match the calculated result of day that should send out notification
var gr2 = new GlideRecord('sn_customerservice_test');
gr2.addEncodedQuery('query');
gr2.query();
while (gr2.next()) {
//send out notifications
}