Adding three business days to due date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2020 09:01 AM
Hi Everyone,
We have opened date and start date fields on the Requested item form. I want to add three working business days to opened date and need to update that result in the start date. For example I was opened a requested item on 12/6/2020, now start date would be updated as 16/6/2020 (Since 13 & 14th dates are Saturday and Sunday, we need to exclude them). Please help me how to do this. Thank you in advance
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2020 09:53 AM
Hi,
I tried with your script, instead of adding three working days, script was adding more then ten days. Please see the below screenshot. Opened date was 06/12/2020 09:49:28 AM and start date was updated as 06/24/2020 09:49:28 AM from the script. Can you please have a look and let me know where i made wrong ?
Script :-
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var days = 3;
var opened = new GlideDateTime(current.opened_at);
var duration = new GlideDuration(60*60*24*1000*days);
var schedule = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); // Use the Existing 8-5 weekday schedules
var updatedDays = schedule.add(opened, duration);
current.expected_start = updatedDays;
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2020 10:03 AM
Hi Goutham,
I tried in my PDI its working fine for me as my script was:
var gr = new GlideRecord('change_request');
gr.get('db341cae2f1d5490d1ea52492799b6d7');
gs.print('created_date'+gr.sys_created_on);
var days = 3;
var creat= new GlideDateTime(gr.sys_created_on); // created date
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days); //calculate duration of three days
var schedule = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); // Use the Existing 8-5 weekday scheues.
var updatedays = schedule.add(creat, dur);
gs.print('Updated days'+ updatedays);
Output was:
As you can see that it added 3 business days.
So I think there is some issue with the schedules which you have used:
The schedule screenshot is : schedule is in (cmn_schedule) table:
The schedule entry :
If this schedule is not present then you can crate a new schedule and use that as the schedule id.
Please mark correct and helpful.
Thanks,
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2020 04:15 AM
Hi,
As you are using schedule of business working days(which has schedule as 8-5 working hours), instead of adding 3 days(=72 hours), you need to add 27 hours(=3 business days [8-5 schedule for a day= 9 hours]) to the opened_at date.
var sched = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae');
var dt = new GlideDateTime(current.opened_at);
var dur = new GlideDuration(27*60* 1000 * hours); //calculate duration of three days = 1 day = 9 hours
var schedule = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); // Use the Existing 8-5 weekday scheues.
var updatedays = schedule.add(dt, dur);
gs.info(updatedays);
Let me know if this resolves your query.
Thanks.