Date Validaion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 11:14 PM
Hi,
I'm working on a form validation where there are two fields in a section both are 'date' fields
field - 1 : u_test1
field - 2 : u_test2
u_test1 should not be greater than u_test2
u_test1 should not be less than today.
can anybody help me on this?
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 11:21 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 12:06 AM - edited 07-25-2023 12:11 AM
Hi you can have 2 onChange Client scripts on test 1 and test 2 fields
Script 1 on test1 field to validate date cannot be today and past days
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.hideErrorBox('u_test_1');
var date = g_form.getValue('u_test_1');
date = new Date(Date.parse(date.replace(/-/g,' ')));
var today = new Date();
today.setHours(0,0,0,0);
if (date <= today) {
g_form.showErrorBox('u_test_1',getMessage('Test1 date cannot be todays date'));
}
}
Script 2 on test 2 field to validate cannot be before test 1 date
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.hideErrorBox('u_test_2');
var start_date = g_form.getValue('u_test_1');
if (start_date) {
var startMS = getDateFromFormat(start_date, g_user_date_format);
var endMS = getDateFromFormat(newValue, g_user_date_format);
if (endMS < startMS)
g_form.showErrorBox('u_test_2',getMessage('Test 2 date must be after test 1 date'));
}
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 12:46 AM
Hello @Atik
You can write a before insert BR using this script,
var date1 = current.u_test1;
var date2 = current.u_test2;
var today = new GlideDate();
if (date1>date2 || date1<today){
gs.addErrorMessage('u_test1 should not be grater than u_test2 and u_test1 should not less than today');
current.setAbortAction(true);
}
Please mark my answer Helpful and accepted solution,
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 01:25 AM
Hello @Atik
Can you try using below condition in UI policy
Please mark this response as correct or helpful if it assisted you with your question.
Regards,
Nitesh