Need to subtract or minus 5 business days from a date/time field on the Catalog form.

Rmohan
Mega Expert

Hi,

I have a requirement for setting a field value as 5 business days minus the set date on the another field on a catalog form.

For example-

If the Delivery_Date is set as 11-15-2019, the Actual_Start_date should be 11-08-2019, taking into account the 8-5 weekday schedule.

Looking for on how to configure the Actual_Start_date.

The delivery date can be modified by the user submitting the request, so I know it should be a catalog client script, but I am quite new to coding and after thoroughly searching the community, could not find the answer I needed.

So requesting the ServiceNow Community for assistance.

Thanks.

1 ACCEPTED SOLUTION

Rmohan
Mega Expert

Hi All,

I finally made is possible by following a minimal scripting method using the Timer.

As suggested by TJW in set a timer in workflow based on a variable, I was able to set the schedule and make the timer wait as per my needs.

Thank you all for your support 🙂 

View solution in original post

39 REPLIES 39

Chavan AP
Kilo Sage

1. write a catalog client script :

 var deliverydate= g_form.getValue('<delivery_date>');//variable filed 

 var ajax = new GlideAjax('AjaxDurCalc');

  ajax.addParam('sysparm_name','durCalc');


  ajax.addParam('sysparm_deliv',deliverydate); 


  ajax.getXMLWait();


  var answer = ajax.getAnswer();


  g_form.setValue('<start_date>', answer);


}

2. script include:

var NofDays = Class.create();


NofDays.prototype = Object.extendsObject(AbstractAjaxProcessor, {


days:function(){


var deliver=this.gertParameter('sysparm_deliv');


var ps = new GlideDateTime(deliver);


  ps.addDays(-5);


  var datebefore =ps.getDate();

return datebefore;





},


      type: 'NofDays'


});

 

 

if this resolves ur query mark correct n helpful

 

ajay

 

Glad I could help! If this solved your issue, please mark it as ✅ Helpful and ✅ Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

Hi Ajay,

Thank you for your response. I tried the method you suggested, however the field Actual_start_date is showing as blank.

Please let me know what I am doing wrong.

Catalog Client Script-

find_real_file.png

 

Script Include-

find_real_file.png

 

Thanks

Check client callable field in script include.

Hi Vignesh,

 

Checked the Client Callable field and still not working.