Restrict user to select a time in the future.

Ramya33
Tera Contributor

In my incident form, there is a field of 'date/time' format. Date validation(i.e restriction on selecting a date in the future) has been done. Kindly help on how to restrict a user to select a time in the future.

 

Thanks!

9 REPLIES 9

Hello ,

 

Try making business rule on update.

 

To get the current time you can do something like this.

var gdt = new GlideDateTime(gs.nowDateTime());

var t1= gdt.getNumericValue();

 

And now use the same getNumericValue function to get value in numeric for your date time field as well and then compare them both.

 

var gdt2 = new GlideDateTime(current.custom_field));

var t2 = gdt2.getNumericValue();

 

if(t2 < t1)

{

gs.addInfoMessage('Value can be set');

}

 

else

{

gs.addInfoMessage('Value set is greater than current time hence action abort');

 

current.setAbortAction(true);

 

}

 

Mark my ANSWER as CORRECT and HELPFUL if it helps.

Let me know if that doesnt work

Ramya33
Tera Contributor

No, that did not work. Anyways, I got it fixed using a UI policy.

Thank You!

Suseela Peddise
Kilo Sage

Hi,

You can achieve this easily using UI policies.

Condition:

<field name>> after <<current minute>> //change according to your requirement

Execute if true script:

alert('Date/Time cannot be in the future');

g_form.setValue('<<field name>>', ''); //clear the value

 

If I have answered your question, please mark my response as correct and/or helpful.

Thanks,

Suseela P.

 

Thanks @Suseela Peddisetty this worked perfectly.