Wednesday, August 22, 2012

Checking condition for last 15 days date using JavaScript in MS CRM


var currentDate = new Date();
var dateOfContact = crmForm.all.new_submissiondate.DataValue;
if(dateOfContact != null)
{
  var pastMaxDate = new Date();

  currentDate.setHours(0);
  currentDate.setMinutes(0);
  currentDate.setSeconds(0); 
  currentDate.setMilliseconds(0);
 
  pastMaxDate.setDate(currentDate.getDate()-14);
  pastMaxDate.setHours(0);
  pastMaxDate.setMinutes(0);
  pastMaxDate.setSeconds(0);
  pastMaxDate.setMilliseconds(0);

  //Checking condition for last 15 days
  if( !((dateOfContact <= currentDate) && (dateOfContact >= pastMaxDate)) )
  {
    crmForm.all.new_submissiondate.DataValue = null;
    alert("Valid date range is from "+ pastMaxDate.toLocaleDateString() + " to till today.");
  }
}

No comments:

Post a Comment