Start date cannot be past date

Deepthi13
Tera Expert

hi team,

i am trying client script as below please correct if any thing wrong here

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var date_obj = new Date(getDateFromFormat(newValue,user_date_time_format));
var current_date=new Date();
if(date_obj<current_date){
g_form.showFieldMsg('Date','Date should not be past value',error,true);
}
else{
g_form.setValue('Date',current_date);
}
//Type appropriate comment here, and begin script below

}

1 ACCEPTED SOLUTION

yes. 

 

Date type variable on catalog form. 

 

find_real_file.png

 

Catalog UI Policy 

 

find_real_file.png

 

find_real_file.png

 

Result: i tried to select the 27th may and it gave me an alert. 

 

find_real_file.png

View solution in original post

14 REPLIES 14

ohk.. give a try with glide ajax. 

 

adding one thread here. kindly read the last comment in below thread. 

 

https://community.servicenow.com/community?id=community_question&sys_id=16bb8ba1db9cdbc01dcaf3231f96...

there are 2 codes which code is correct ? can u paste here please

Script include:

 

var NowDateCalc = Class.create();


NowDateCalc.prototype = Object.extendsObject(AbstractAjaxProcessor,{



getNow : function() {


return gs.now();



},


       type: 'NowDateCalc'


});

 

Client script:

 

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


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


           return;


     }
  
var start_date = g_form.getValue('start_date');

var ga = new GlideAjax("NowDateCalc");

ga.addParam("sysparm_name", "getNow");

ga.getXMLWait();

var rightNow = ga.getAnswer();

if ( start_date < rightNow) {

g_form.clearValue('start_date');

alert("Start date by cannot be earlier than today.");


}


}

Hi harsha,

i am getting alert for past day selction. 

even for future day selection. basically that is happening for any date selection, today , yesterday or tommarow

are you doing it on Personal instance ? if yes then i can quickly help you. 

is it possible to share your screen on google hangout ?

 

because i tested with UI Policy or even with client script it is working for me.