- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2015 04:00 AM
I've seen this in the community where this is working for others, but it's not working for me. What do I have wrong? I get no error message. It's just ignored.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue != '')
{
var reqDate = new Date(getDateFromFormat(newValue, g_user_date_format));
var today = new Date();
if(reqDate.getTime() <= today.getTime()) {
alert('Date must not be in the past.');
g_form.setValue('sDate', '');
}
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2015 07:45 AM
Hi Karen,
You are just comparing the time. You should first compare date and then time. Or both at the same time.
Try with the below shown code-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
// if(newValue != '') don't need this as you already have checked above
// {
var reqDate = new Date(newValue);
var today = new Date();
if(reqDate <= today){
alert('Date must not be in the past.');
g_form.setValue('closed_at', '');
}
// }
}
Thanks,
Tanaji

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2015 07:45 AM
Hi Karen,
You are just comparing the time. You should first compare date and then time. Or both at the same time.
Try with the below shown code-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
// if(newValue != '') don't need this as you already have checked above
// {
var reqDate = new Date(newValue);
var today = new Date();
if(reqDate <= today){
alert('Date must not be in the past.');
g_form.setValue('closed_at', '');
}
// }
}
Thanks,
Tanaji

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2015 07:51 AM
Use GlideAjax for more flexibility and for better precision.
Check out Client Script Date/Time Functions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2015 09:12 AM
A change needed as its a variable.
Replace line
g_form.setValue('closed_at', '');
with
g_form.setValue('variables.sDate','');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2015 09:15 AM
I found it. I had forgotten to populate the Variable Name field on the top section of the Catalog Client Script form. No wonder it was ignoring the script... beginners mistake. Thanks everyone for the help. It's now working.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2015 09:17 AM
Perfect
Can you please mark the response if this answers your question.