- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2020 05:44 AM
I have another item where I have set the due date to 10 business days from the opened date of the item, however I have a little more tricky one. I need to take the date/time from a variable(date_time_deployment) the user selects and add 3 business days and 4 hours to it for the due date. I put together this script to get the 3 days as a start but it's not working correctly. Any ideas on how to get this accomplished? I'm using a business rule to accomplish this.
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name', '8-8 weekdays excluding holidays');
if (typeof GlideSchedule != 'undefined')
var sched = new GlideSchedule(schedRec.sys_id);
else
var sched = new Packages.com.glide.schedules.Schedule(schedRec.sys_id);
//Get the current date/time in correct format for duration calculation
var currentDateTime = current.variables.date_time_deployment;
//Set the amount of time to add (in seconds)
var timeToAdd = 3 * 43200;
durToAdd = new GlideDuration(timeToAdd*1000);
var newDateTime = sched.add(currentDateTime, durToAdd, '');
//Set the 'due_date' field to the new date/time
current.due_date = newDateTime;
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2020 01:22 PM
If its a business rule on Requested Item [sc_req_item] table then
current.variables.date_time_deployment
should give you the value.
I tested and this code should work for you.
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name', '8-8 weekdays excluding holidays');
if (typeof GlideSchedule != 'undefined')
var sched = new GlideSchedule(schedRec.sys_id);
else
var sched = new Packages.com.glide.schedules.Schedule(schedRec.sys_id);
//Get the current date/time in correct format for duration calculation
var currentDateTime = new GlideDateTime();
currentDateTime.setDisplayValue(current.variables.date_time_deployment);
//Set the amount of time to add (in seconds)
var timeToAdd = 3 * 43200 + 4 * 3600;
durToAdd = new GlideDuration(timeToAdd*1000);
var newDateTime = sched.add(currentDateTime, durToAdd, '');
//Set the 'due_date' field to the new date/time
current.due_date = newDateTime;
In case you are writing this BR in after or async then dont miss to add this line at the end of above script.
current.update();
-Tanaji
Please mark response correct/helpful if applicable

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2020 06:16 AM
Could you try replacing this line?
var currentDateTime = current.variables.date_time_deployment;
with
var currentDateTime = current.variables.date_time_deployment.getGlideObject();
Assuming 8-8 in your schedule means 8 am to 8 pm (i.e. 12 hours a day) the calculations should look like-
//Set the amount of time to add (in seconds)
var timeToAdd = ((3 * 12) + 4) * 60 * 60;
-Tanaji
Please mark reply correct/helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2020 06:51 AM
This set the due date to 2 days from the current time, but not the one selected in the variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 10:09 PM
Hello booher04,
Please refer below links, this might help you:
If my answer is helpful to you,please mark answer as helpful and correct.
Thanks and regards,
Megha.