The CreatorCon Call for Content is officially open! Get started here.

start date should be today + 2 business days

Thomas99
Tera Contributor

Posting this again as I could not get it working:

 

Hi

 

Can someone please help me with catalog client script (on change) and script include

 

I have a date variable in the new hire form.

The requirement is users should only be allowed to select the "start date" as current date + 2 business days (exclude sat-sun). 

 

Example: If I'm filling the form today , (Oct 11) the start date should be Oct 14 or further. User should not be be able to select an ealier date and should give an error " Invalid date" 

 

Thanks,

21 REPLIES 21

Hi @Thomas99 

It took me a while to come back and check on this 🙂

 

I tried the below code and it worked fine for me even during the weekend.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ga = new GlideAjax('ValidateDate');
    ga.addParam('sysparm_name', 'dateValidation');
    ga.addParam('sysparm_date', newValue);
    ga.getXML(CallBack);

    function CallBack(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer == 'true') {
			g_form.setValue('lpar_refreshed', '');
			g_form.showErrorBox("lpar_refreshed", "pls select atleast 48hrs or more from now");
        }
    }
}

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

Thanks,
Anvesh

Harsh_Deep
Giga Sage
Giga Sage

Hello @Thomas99 

You should calculate the duration based on a schedule to get the business duration. Try the below script in script include.

 

var ValidateDate = Class.create();

ValidateDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {

  dateValidation: function(){

      var selected_date = new GlideDateTime(this.getParameter('sysparm_date');

      var today = new GlideDateTime();

      var schedule = new GlideSchedule();

      schedule.load('090eecae0a0a0b260077e1dfa71da828'); // loads "8-5 weekdays excluding holidays" schedule

      var duration = schedule.duration(today, selected_date);

      var days = duration.getRoundedDayPart();

      if(days > 2){

          return 'true';

      }

      return 'false';

  },

 

  type: 'ValidateDate'

 

});

 
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.