Date/Time Field Restriction Record Producer

Sam Ogden
Tera Guru

Hi All,

I have a date/time field on a record producer asking when the incident first occurred.

I have seen that the only way yo restrict this so people cannot add a date in the future is to have a script which validates this between the current date and the date selected when the field changes and then have a pop up message to warn the user.

I'm just not sure on how to script this?

Any help is greatly appreciated.

Thanks

37 REPLIES 37

Hi Shloke,



I've also been trying Balaji's suggestion further up but can't seem to get either to work, have you any further suggestions?



Thanks


preddy
Kilo Guru

Hi Sam,



For this you need to Write Script Include and Call that script Include in onChange Catalog Client Script on record producer.



Script Incldue:



var DateValidation = Class.create();


DateValidation.prototype = {


      checkingFutureDate: function() {


              return (gs.dateDiff(gs.nowDateTime(),this.getParameter('sysparm_startDate'),true));      


      },


 


      type: 'DateValidation'


};



Catalog Client Script:



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if (isLoading || newValue === '') {


          return;


    }


      g_form.hideFieldMsg("date variable");


      var test = new GlideAjax('DateValidation');


      test.addParam('sysparm_name','checkingFutureDate');


      test.addParam('sysparm_start_date',newValue);


      test.getXMLWait();


      var answer = test.getAnswer();


      if(answer < 0 )


              return true;


      g_form.showFieldMsg("date variable","Date Should not be a Future Date");


   


      return false;


     


}



If this is Helpful Please Hit that helpful to you


Hi Pavan,



I've just tried the above, however the Msg is showing if the date selected is in the future or not.   I've added below the script:



Script Includes:


find_real_file.png


Client Script:



find_real_file.png


preddy
Kilo Guru

Hi Sam,


I saw the client script you are calling Script include in GlidaAjax but the is Different, Can you please change the name try it once again.



function onChange(control, oldValue, newValue, isLoading) {


      if (isLoading || newValue == '') {


              return;


      }


      g_form.hideFieldMsg("u_date");


      var test= new GlideAjax('CDLDateValidation');


      test.addParam('sysparm_name','checkingFutureDate');


      test.addParam('sysparm_date',newValue);   // Hi Sam can you check it script include this parameter is Correct or not.


      test.getXMLWait();


      var answer = test.getAnswer();


      if(answer < 0 )


              return true;


      g_form.showFieldMsg("u_date","Date and Time of Admission should not be in future date.","error");


      return false;


     


      //Type appropriate comment here, and begin script below


     


}



If this is Helpful Please Hit that helpful to you


Hi Pavan,



I've checked the script include and client script, now as below, however it is still showing the message even when the date is not in the future?



find_real_file.png


Script Includes:


var CDLDateValidation = Class.create();
CDLDateValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {


checkingFutureDate: function() {
              return (gs.dateDiff(gs.nowDateTime(),this.getParameter('sysparm_Date'),true));      


      },


      type: 'CDLDateValidation'
});


Client Script:



function onChange(control, oldValue, newValue, isLoading) {


      if (isLoading || newValue == '') {


              return;


      }


      g_form.hideFieldMsg("u_date");


      var test= new GlideAjax('CDLDateValidation');


      test.addParam('sysparm_name','checkingFutureDate');


      test.addParam('sysparm_date',newValue);


      test.getXMLWait();


      var answer = test.getAnswer();


      if(answer < 0 )


              return true;


      g_form.showFieldMsg("u_date","Date and Time of Admission should not be in future date.","error");


      return false;


}