- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2021 04:36 AM
Can anyone please advise about how to calculate a certain number of BUSINESS days from today's date?
USE CASE:
Phone Decommissioning: I need to use a 'date' variable where user needs to add a date that is not earlier than 10 business days from today.
I would need to create a script include function that I can then pull in a GlideAjax.
At the moment, I am using this utility function to calculate the calendar days and it works correctly, if wanting to calculate ONLY calendar days, not BUSINESS days:
isSelectedDateAfterCertainDays: function() {
if (JSUtil.nil(this.getParameter('sysparm_selectedDate')) || JSUtil.nil(this.getParameter('sysparm_days'))) {
return false;
}
var gdt = new GlideDateTime(gs.nowDateTime());
var selectedDate = this.getParameter('sysparm_selectedDate');
var ed = new GlideDateTime(gdt);
ed.addDays(this.getParameter('sysparm_days'));
var diff = gs.dateDiff(ed, selectedDate, true);
if (diff > 0)
return 'true';
else
return 'false';
},
Went through numerous articles here, even the long-running helpful article by MB found here, but honestly, being a coding beginner, I would very much appreciate help with creating a script include function that would calculate the date EXCLUDING the weekends....
Can anyone help, please?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2021 04:23 AM
i updated the code with glide schedule. Make sure to create a valid scheduled cmn_scheduled table for weekdays and pass that sys_id into glideschedule
isSelectedDateAfterCertainDays: function() {
if (JSUtil.nil(this.getParameter('sysparm_selectedDate')) || JSUtil.nil(this.getParameter('sysparm_days'))) {
return false;
}
var selectedDate = this.getParameter('sysparm_selectedDate');
var gdt = new GlideDateTime(selectedDate);
var ed = new GlideDateTime();
var days =this.getParameter('sysparm_days')
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var schedule = new GlideSchedule('38fa64edc0a8016400f4a5724b0434b8'); //sys_id of schedule cmn_schedule table
var end = schedule.add(ed, dur);
var diff = end.before(gdt);
return diff;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2021 04:50 AM
try this
isSelectedDateAfterCertainDays: function() {
if (JSUtil.nil(this.getParameter('sysparm_selectedDate')) || JSUtil.nil(this.getParameter('sysparm_days'))) {
return false;
}
var selectedDate = this.getParameter('sysparm_selectedDate');
var gdt = new GlideDateTime(selectedDate);
var ed = new GlideDateTime();
ed.addDays(this.getParameter('sysparm_days')); //10 days from now
var diff = ed.before(gdt);
return diff;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2021 05:01 AM
Hi
It only calculates 10 WORKING days, not 10 BUSINESS days from now on.
It actually works correctly, but so does mine code above.
I am looking for a solution to calculate 10 business days from today's date...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2021 05:08 AM
Oh, sorry i interpreted something else.
You have to use schedule and GlideSchedule API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2021 06:04 AM
Dear
It's quite hard for me to modify the script myself, that is why I kindly asked for help here..