Catalog Client Script - Exclude Weekends

Syn C
Kilo Contributor

Hi, I am currently trying to build a catalog client script but I am having trouble.

We have a request that if on the date field if a user selects a date that is within 2 business days from the current date then a new field with display.  The problem is in using the UI Policy we cannot exclude weekends.  So I knew that I could do it using a catalog client script but I am having trouble call the script include so that I can reference the setSchedule.

Any help would be appreciated.

 

10 REPLIES 10

ccajohnson
Kilo Sage

It sounds like you have already created a Script Include that will be used to determine if the date is within 2 business days. Make sure that your Script include has Client callable checked, and to have Accessible from set to be All application scopes.

Please share what you have so far so we can assist in your solution.

Syn C
Kilo Contributor

I do not have a script include for determining what days. I am using the include DurationCalculator as this already has the setSchedule for our company.  

 

I want to create an if statement within the client script that basically excludes weekends only recognizes business days.  So 2 days from Thursday is Friday and Monday (hopefully this makes sense).

This is what I have so far, but I am not sure what I am missing.

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

var today = new Date();
var ga = new GlideAjax('DurationCalculator');
ga.addParam('sysparm_name', 'setSchedule');
ga.addParam('sysparm_sid', '338db49d300fddlajfdljfaklfjkldj');
ga.getXML(getDays);
	

}

function getDays(response) {



       var answer = response.responseXML.documentElement.getAttribute("answer");



       g_form.setValue('bus_days', answer);



}

 

 

Based upon what you show, I am now confused. Are you wanting to populate a field, or just make it visible?

What I think you want to accomplish is to calculate now to 2 business days ahead, then compare it with the selected date. If the selected date is within 2 business days from now, then make a variable visible, otherwise do not show the variable.

Calculating dates against a schedule is not something that can be done within a Catalog Client script. The DurationCalculator script include is not client callable from what I can tell, and what you are attempting to do I am not sure will return any results.

Please let me know if I am correct in your ask so I can adjust my Date Time Utility script include accordingly and offer a viable solution. 

Syn C
Kilo Contributor

I apologize for the confusion, but you are correct.

Thank you for any help you can provide.