- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 09:18 AM
Hello,
I have 3 date fields on my record producer.
1) Start date - 'pay_period_start'
2) End date - 'pay_period_end'
2) Date - 'date'
I need to compare the 'date' with the Start Date & End date. This will decide what happens on the form. Here is my on change client script so far. it is not working:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var dateValue = g_form.getValue('date');
var start = g_form.getValue('pay_period_start');
var end = g_form.getValue('pay_period_end');
if (dateValue < start || dateValue > end) {
g_form.showFieldMsg('date', ':Please provide an explanation.', 'error');
g_form.setVisible('past_date_hours_explanation', true);
g_form.setMandatory('past_date_hours_explanation', true);
}
else {
g_form.hideFieldMsg('date');
g_form.setMandatory('past_date_hours_explanation', false);
g_form.setVisible('past_date_hours_explanation', false);
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 10:14 AM
use glide ajax here, and in client callable script include compare it, based on that return true or false , you will get more flexibility in date comparison if you will use script include + glideajax.
sample code mentioned in below thread.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 09:27 AM
what's not working here ?
is it going inside the if block ? can you add some alert inside the if block
updated script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var dateValue = g_form.getValue('date');
var start = g_form.getValue('pay_period_start');
var end = g_form.getValue('pay_period_end');
if (dateValue < start || dateValue > end) {
alert('coming inside if ');
g_form.showFieldMsg('date', ':Please provide an explanation.', 'error');
g_form.setVisible('past_date_hours_explanation', true);
g_form.setMandatory('past_date_hours_explanation', true);
}
else {
alert('coming inside else ');
g_form.setMandatory('past_date_hours_explanation', false);
g_form.setVisible('past_date_hours_explanation', false);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 09:39 AM
it is not comparing the date fields correctly. No matter what 'date' is selected the 'if' code is still executing. Very confused.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 09:45 AM
can you break your condition for just troubleshooting your script ,
eg: first check dateValue < start and see are you getting if block alert or not , if you will get
then check for dateValue > end using inside the if block ,
let me know the first condition is working here or not, date field value should be less than pay_period_start field value ,
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var dateValue = g_form.getValue('date');
var start = g_form.getValue('pay_period_start');
var end = g_form.getValue('pay_period_end');
if (dateValue < start ) {
alert('coming inside if ');
g_form.showFieldMsg('date', ':Please provide an explanation.', 'error');
g_form.setVisible('past_date_hours_explanation', true);
g_form.setMandatory('past_date_hours_explanation', true);
}
else {
alert('coming inside else ');
g_form.setMandatory('past_date_hours_explanation', false);
g_form.setVisible('past_date_hours_explanation', false);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 09:50 AM
when I just use: if (dateValue < start) No matter what date I select the IF always executes
When I just user: if (dateValue > end) No matter what date I select the ELSE always executes
The < & > signs are not comparing the date variables properly