- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 02:02 PM - edited 05-31-2023 02:19 PM
Hi all,
I want to send report on Last business day of Month, kindly help me how to fix this issue.
var sched = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); // Check Business day, Exculde Holidays and Weekends //
var d = new GlideDateTime('2023-04-12');
var total_days = d.getDaysInMonth();
var abc = false;
var last_business_day = '';
d.setDayOfMonth(total_days);
while(!abc){
abc = sched.isInSchedule(d);
if(!abc){
d.addDays(-1);
}
}
var business_day = new GlideDateTime(d).getDate();
gs.info('business_day : '+business_day);
Here I have taken 'April 2023' month , as per above script I'm getting Last working day is 'April 29th' , but April 29th is Saturday.
Please help me how to get right Last business Day of Month. what is wrong in my code.?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 07:00 AM
@Supriya25 Use this updated code for both current date and future date testing.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 08:02 AM
your code is working .....
help on below one
new GlideDate+" 10:00:00";
" 10:00:00" why you are adding ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 08:06 AM
@Supriya25 Add "10:00:00" because the schedule is from "8:00:00" to "17:00:00".
So to check if the date is in schedule we need to check the time should fall between 8am to 5pm.
Hence hard coded it.
Hope it is clear.
Please check that and mark all answers as correct answers if those helped you
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 08:28 AM
so In place of '10:00:00' I can take any like "09:00:00" or 16:00:00 Or 23:0:00... like this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 09:17 AM
@Supriya25 9 and 16 will be in schedule
23 will not be in schedule
You have to use any time between 8 am to 5 pm
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 09:34 AM
thanks for your replies on my quires.
my last query below one.
1.what will happens if we take times before 9 and after 16 ( like 20:00:00, or 07:00:00) ???
2.why do take time, can't we use new GlideDateTime() please ?