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

no i am doing in client instance only 😞

is that date field u tried in ur instance?

could you please provide ur screen shots

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

How to handle the same on the list view for Variable?

kumar22
Tera Contributor

Hi Deepthi,

Write a script include with client callable is true

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

nowDateTime: function () {
return gs.now();
},
type: 'MyDateTimeAjax'
});

Write a Onchange client script with below code:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var ajax = new GlideAjax('MyDateTimeAjax');
ajax.addParam('sysparm_name','nowDateTime');
ajax.getXML(checkdate);
function checkdate(response){
var currentDate = response.responseXML.documentElement.getAttribute("answer");
var startDate90 = g_form.getValue('return_date'); //Change the required date field name
if(startDate90 < currentDate){
alert('You cannot select a date in the past.');
g_form.clearValue('return_date');
}
}
}

Thanks,

Okay, so this is for date... but what do we do to restrict selection of past time?

for Date/Time field.