
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 03:02 AM
Hi Team,
I have a requirement where I need to add no.of days to approved date excluding weekends and show the same on a date field. For this I'm trying below background script but it is not going inside " if " after for loop. Let me know if any mistakes and modifications required.
var due = '3';
var approved = '2020-05-23 11:57:41';
var gdt = new GlideDateTime(approved);
gs.print(gdt);
for(var i=0; i<due;i++){
var schedule = new GlideSchedule("08fcd0830a0a0b2600079f56b1adb9ae")
gs.print('inside for');
if(schedule.isInSchedule(gdt)){
gs.print('if');
gdt.addDays(1);
}
else{
gdt.addDays(1);
}
}
if(i==due){
gs.print(gdt.getDate());
}
Any quick response will be appreciated. Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 03:20 AM
Hi,
So based on 8-5 Weekdays schedule you need to add 3 days and exclude weekends from that?
Since 8-5 Weekdays doesn't include weekends you need not check that
please use below script; it should give 4th june
var days = 3;
var approved = '2020-05-23 11:57:41';
var approvedGdt = new GlideDateTime(approved);
gs.info(approvedGdt);
var dur = new GlideDuration(60*60*24*1000*days);
var schedule = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae');
var finalTime = schedule.add(approvedGdt, dur);
var value = finalTime.getDate();
gs.info(value); // output as 2020-06-04
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 04:36 AM
Hi,
Refer this link
Please mark it correct and helpful if applicable.
Thanks,