Service Catalog- Restricting Time in Date Field

book

Article ID: 142221

calendar_today

Updated On:

Products

CA Service Catalog

Issue/Introduction

Need to know if there is a way to restrict times a user can select from a Date/Time field in a form within Service Catalog. Example: A user would like times from 1am - 7am unable to be selected so tickets are not created and expected to be completed at that time. 

Environment

Release : 17.2

Component : CA SERVICE CATALOG

Resolution

If you want to  allow any date but only time to be restricted, this can be done using form script in 'onvalidate' attribute  for the date field in the form  by checking the time value and  instructing the user to select between the allowed time range.


Example:

 

form script:

{
  validate : function(val){
    var millis = ca_fdGetDateFieldValueInMillis(ca_fd.formId,'date_1');
    if(millis < (new Date().setHours(0,0,0,0)+3600000) || millis > (new Date().setHours(0,0,0,0)+25200000)){
       return 'Time Range must be between 1 AM and 7 AM only';
       }
  }
}

 

onValidate : ca_fd.js.validate(_val);

 

 

 

the above is  set to only allow the time range between 1:00am to 7:00am .