- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2022 01:57 PM
I would LOVE a second set of eyes on my code. I am trying to write an onSubmit client script that compares my due_date field to yesterday (24 hours ago). I have converted both to milliseconds, and the values appear to be correct. Then if due_date < yesterday, I want to display an error message and prevent the user from saving.
If I enter a date that is less than yesterday, and submit, I get the error message. If I then immediately enter yesterday's date and submit, I still get the error.
Here's the code:
function onSubmit() {
var now = new Date();
var yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
var y = yesterday.getTime();
var due1 = g_form.getValue('due_date');
var due = getDateFromFormat(due1, g_user_date_format);
if (due < y) {
g_form.addErrorMessage('The Planned Review Date should be no earlier than yesterday.');
return false;
}
else g_form.addInfoMessage('Passed.');
}
Thanks a ton for any assistance!!!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2022 10:33 AM
Yes, that was my original statement. Thanks for pointing that out!
I changed it so much that I missed the actual fix, which was flipping the formats for yesterday and due:
var yesterday_str = formatDate(yesterday, g_user_date_time_format);
var due = g_form.getValue("due_date");
Changing each field's format is what did the trick and actually allowed the comparison to function correctly.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2022 12:15 AM
Hi Digit
The problem is with "g_user_date_time_format". Field "due_date" is of type "Date" so it should be "g_user_date_format".
function onSubmit() {
var now = new Date();
var yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
var y = yesterday.getTime();
var due1 = g_form.getValue('due_date');
var due = getDateFromFormat(due1, g_user_date_format);
if (due < y) {
g_form.addErrorMessage('The Planned Review Date should be no earlier than yesterday.');
return false;
} else {
g_form.addInfoMessage('Passed.');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 06:04 AM
Thanks for the feedback, but "due_date" is actually a date/time field.
I tried changing it to
var due = getDateFromFormat(due1, g_user_date_format);
in order to see if it made any difference, and unfortunately I got the same results.
Both final fields produce a numeric value in milliseconds, but for some reason, they never pass, regardless of what date I try.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 09:32 AM
Just discovered the answer, for any future folks looking for assistance on a related issue.
I changed this original line:
var due = getDateFromFormat(due1, g_user_date_format);
to:
var due = getDateFromFormat(due1, g_user_date_time_format);
and everything then worked correctly.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 09:45 AM
Hi,
I may be missing something, but you already had that line in your original post?
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!