How to restrict date variable to only allow selecting a date that is 5 days from today and onwards?

alberttagle
Tera Contributor

Hi,

Please help me script.  I have date field named startdate, but I need for users not to be able to select any date before 5 days from today.

Thanks!

1 ACCEPTED SOLUTION

Here's my OnChange Client Script that calls the same Script Includes (with the original name however) requiring that a due date is greater than 5 days out (note it is in seconds):

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
 
 
  var cdt = g_form.getValue('due_date'); //First Date/Time field 
 
  var ajax = new GlideAjax('ClientDateTimeUtils'); 
  ajax.addParam('sysparm_name','getNowDateTimeDiff'); 
  ajax.addParam('sysparm_fdt', cdt); 
  ajax.getXML(doSomething); 
 
  function doSomething(response){ 
  var answer = response.responseXML.documentElement.getAttribute("answer"); 
  //5 days out
	  if (answer < 431000)
  {
  alert('The lead time to process this request is 5 days.' + '\n' +  'If this is an urgent request please contact the Service Desk for assistance escalating this request.');
	  //alert('The date value cannot be before 5 days into the future. Please correct.');
  //g_form.clearValue("due_date");
  }
  
  }
}

View solution in original post

6 REPLIES 6

Krish14
Mega Contributor

Shane, I'm having similar situation. Can you please help me in blocking future two weeks from the current date and all the past dates.

Shane

 

Any idea why I can't get this to clear the date and also I need 30 days out and no matter what I pick

I get the pop up window