Restrict user to select a time in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2020 08:45 PM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2020 09:44 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2020 03:34 AM
Let me know if that doesnt work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2020 03:42 AM
No, that did not work. Anyways, I got it fixed using a UI policy.
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2020 03:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2020 10:16 AM
Thanks