How to force a date to be less than 90 days in the past in a Record Producer?

htank66
Kilo Contributor

Nothing special with schedules or anything, just straight up no further than 90 days in the past.  If the user tries to make it a date that is further than that maybe a pop-up tells them it is not possible and clears the field?  Unless there are any other ideas or solutions.

Thank you in advance!

10 REPLIES 10

asifnoor
Kilo Patron

Hi,

Write a client script onchange on the date field which you want to validate.

Add the below code in that function. Change the field names wherever applicable.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
  //Type appropriate comment here, and begin script below
   var selectedDateNum = getDateFromFormat(newValue, g_user_date_format);  //This gives the selected date
   var ninety_days =129600; //90 days in minutes
   var ninety_days_date = new Date(new Date().getTime() - ninety_days*60000);
   var ninety_days_dateStr = formatDate(ninety_days_date, g_user_date_format); 
   var ninety_days_dateNum = getDateFromFormat(ninety_days_dateStr, g_user_date_format);
   if(selectedDateNum < ninety_days_dateNum) {
       g_form.showErrorBox("YOUR_FIELD","Selected date cannot be less than 90 days",true);
   }
}

Mark the comment as a correct answer and also helpful once worked.

htank66
Kilo Contributor

Changed this code to OnSubmit and added "return false;" after the last night and was able to prevent the form from submitting without the user changing the field to within the ninety days.

htank66
Kilo Contributor

As doing further testing, my update did not work as expected.  The code seems to prevent a date being selected at all, no dates are going through... sorry for the impromptu correct answer.  Any thoughts?

On change, just when you move from that field, the script will validate and returns the error if the date is < 90 days of the current date. If not, then it will simply go through.

I assume your field is datetime data type, not just date.