Set RITM Due Date to date/Time variable plus 3 days 4 hours

booher04
Tera Guru

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;

1 ACCEPTED SOLUTION

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

View solution in original post

12 REPLIES 12

Tanaji Patil
Tera Guru

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

This set the due date to 2 days from the current time, but not the one selected in the variable.

Megha Padale
Giga Guru

Hello booher04,

Please refer below links, this might help you:

https://community.servicenow.com/community?id=community_question&sys_id=53ce3ea5db58dbc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=94fd07addb9cdbc01dcaf3231f96...

If my answer is helpful to you,please mark answer as helpful and correct.

Thanks and regards,

Megha.