The CreatorCon Call for Content is officially open! Get started here.

How to prevent a user from selecting a date in the past for date/time variably type??

gnunez
Kilo Guru

Hello all,

We have a couple of catalog items that use the date variable type and we want to restrict the user's from selecting a date in the past. Is this possible?

Also, we have Start Date and End Date on one our catalog items, does anyone know if its possible to restrict the end date to show dates past the selected start date?

Any suggestions are greatly appreciated!

Thanks,

Grace

1 ACCEPTED SOLUTION

Munender Singh
Mega Sage

Hi,

Kindly use this code:

Suppose the  variable/field name is 'current_date' on the catalog item/form


---'OnChange' Client Script 

--field name : current_date

-Script :
function onChange(control, oldValue, newValue, isLoading)
{
if(isLoading)

{

 return;

}

//start the validation


if(newValue != '')

{
var ga = new GlideAjax('ConfirmDate');
ga.addParam('sysparm_name', 'chkCurrDate');
ga.addParam('sysparm_date',g_form.getValue('current_date'));
ga.getXML(NewParse);
}
function NewParse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'false'){
alert("Date selected is a past entry.");
g_form.setValue('current_date', ''); // Setting the variable as empty
}}}

----Script include  :-

---Name : ConfirmDate
--Client callable : true
-Script :


var ConfirmDate= Class.create();
ConfirmDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
chkCurrDate : function() {

var start = this.getParameter('sysparm_date');
var currDay = gs.now();
if(start < currDay){
return false;
}
else
{ return true; } } });

 

regards,

Munender

 

**Kindly hit correct/helpful if found useful

View solution in original post

16 REPLIES 16

thanks - I had actually found that one also and updated 🙂

This code doesn't work on 

 

dd/mm/yyyy format or any other with dd.mm.yyyy  .

 

Please , check it once again .

 

When you select any previous date of current month it will work , but it you select any previous date of previous month it won't work.