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 Ankur, 

 

I still could not get the weekend thing working. I'm kinda overwhelmed with all the responses I've got, so far it has not worked.  Hope you could help me fix my script. 

 

 

 

Here is my catalog client script:

 

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'){
  alert("pls select atleast 48hrs or more from now");
  g_form.setValue('lpar_refreshed','');
  }
  }
}
 
 Script include: 
 
var ValidateDate = Class.create();
ValidateDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
  dateValidation: function(){

  return (gs.dateDiff(gs.nowDateTime(),new GlideDateTime(this.getParameter('sysparm_date')), true)/3600<48);//change the value according to ur requiremet

  },

  type: 'ValidateDate'

});
 
 
 
 

Hi @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'

 

});

Thanks,
Anvesh

That did not work 😞 

 

I had a syntax error on below line 

 var selected_date = new GlideDateTime (this.getParameter('sysparm_date');
 
so I changed it to 
 
 var selected_date = new GlideDateTime (this.getParameter('sysparm_date'));

 

I have also validated the sysID of the schedule. 

 

 

 

 

 

could you please look at my script include? I dont seem to get it working 😞 

Sayali Gurav
Kilo Sage

 

You can try it by creating onChange catalog client script :

 

Note : in  condition please mention (dayDiff < 2.0) instead of (dayDiff < 7.0)

SayaliGurav_0-1696509152364.png

Mark helpful & correct if applicable.

Thanks & Regards,

Sayali Gurav