Skip to main content
Inspiring
February 26, 2019
Question

CONFIRM SEQUENTIAL DATE ENTRIES

  • February 26, 2019
  • 1 reply
  • 406 views

I am attaching an image of a portion of a log page. As you see, there are multiple (six) identical records - each has a date field.

I need to do two things: 1) Assure that the date being entered does not predate the date field in the previous record, and 2)

verify that there is indeed a date in the date field of the previous record (avoid skipping records). Here is some code I have tried, but I cannot get the if condition to work:

Please share your thoughts.

//THIS VALIDATES THE DATE ENTERED

var cMsg = "The date you entered is invalid.\n\nPlease enter a date that does not pre-date the previous entry date.";

var nIcon = 0;

var nType = 0;

var cTitle = "DATE ERROR";

var str = event.target.name;

var res = str.charAt(str.length-1);

var d1 = Date.parse(this.getField("0." + (res-1)).value);

var d2 = Date.parse(event.value);

if (d1 == 0) {

if (d1 > d2) {

app.beep();

app.alert(cMsg, nIcon, nType, cTitle);

event.value = "";

}

} else {

var cMsg = "This is an invalid entry\n\nThe previous date entry cannot be empty.\n\nPlease use the entry above first.";

app.beep();

app.alert(cMsg, nIcon, nType, cTitle);

}

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
February 26, 2019

Date.parse("") does not return 0. It returns NaN.
I suggest you check if the value of the field equals an empty string directly, instead of this roundabout way.

try67
Community Expert
Community Expert
February 26, 2019

Another thing you're missing is the check whether the field number ("res") equals 1, because if it is then you shouldn't try looking for the previous field, as there isn't one.