how to set due date(only business days should be calculated) on ritm based on catalog variable

eshwar10
Giga Contributor

Hello Guys,

I am current developing a catalog item called EAI DPC request. In that there is a variable service needed which has 4 options as shown belwofind_real_file.png

When the 1st option is selected, the due date on the RITM should be calculated to 8 business days. Right now I have written run script on workflow as below

\

if (current.variables.request_type == '1' && (current.variables.distributed_code == 'Yes' ||current.variables.services_mainframe_codes == 'Yes' )){

var gdt = current.due_date.getGlideObject();

gdt.addDays(4);

current.due_date = gdt;

}

The above code is working, but it is calculating concecutive days and not business days as show below:

find_real_file.png

as you can see, it is not calculating the business days.

Kindly share your views on how can I fix this issue.

1 ACCEPTED SOLUTION

eshwar10
Giga Contributor

i got it guys, I used the below code and it is working.



var schedRec = new GlideRecord('cmn_schedule');


schedRec.get('name', '8-5 weekdays');


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.opened_at.getGlideObject();




//Set the amount of time to add (in seconds)


var timeToAdd = 8 * 32400;


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;


View solution in original post

2 REPLIES 2

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi,



take a look here we I do pretty much the same thing. Got a date and in this example I want to have it 3 business days later, but I think you got the idea. Just ask if you there is something that you wonder about.



How to close ticket after 3 business days



//Göran


eshwar10
Giga Contributor

i got it guys, I used the below code and it is working.



var schedRec = new GlideRecord('cmn_schedule');


schedRec.get('name', '8-5 weekdays');


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.opened_at.getGlideObject();




//Set the amount of time to add (in seconds)


var timeToAdd = 8 * 32400;


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;