These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Date Validation Question

buckynwd
Registered: Jan 6 2011
Posts: 11
Answered

I'm tryint to write formcalc script to validate dates. Basically, based on a specific value in a drop-down field and today's date the date in the 3rd form can't be more than 2 weeks from today. This is what I've got so far. Where am I going wrong?
 
var DateTimeField1 = Num2Date(DateTimeField1, "MMM DD, YYYY")
var $ = Num2Date($, "MMM DD, YYYY")
 
if (OEDCode == "5" and HasValue($)) then
(Date2Num($ - DateTimeField1)) <= 14
else
$.rawValue = num2date(date(), DateFmt(2))
endif
 
Thanks.

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Are you getting any errors?

I would not use the "$" symbol as a variable since it is used to identify the focused field.

George Kaiser

buckynwd
Registered: Jan 6 2011
Posts: 11
You're right. I changed the variable to the field name. I don't get any script errors, but when I enter any value I get a validation error even though the values follow the script.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
A validation script ends generating either a true or false value, and if true does not create a formatted value. From the 'Scripting Reference' under LiveCycle Desinger's 'Help' menu option:

validate event

Description

Initiates when the form design and data merge to create your form and when a field loses focus; for example, when a form filler clicks or uses the Tab key to exit a field. This event initiates again each time the value of a field changes. Calculations and scripts placed on the validate event provide a method to perform validations that are more specific than those available through the Value tab of the Object palette.

Calculations and scripts on the validate event are required to return true or false (expressed in a format appropriate to the scripting language) corresponding to a validation that succeeds or fails, and must not affect the overall form structure of form values. In addition, calculations and scripts should not attempt to provide feedback to a form filler because that form filler may not be using the form in a client application such as Acrobat.

Because validations are performed against the content of the form, they cannot be used to verify presentation formatting caused by field patterns.

George Kaiser

DaveyB
Registered: Dec 10 2010
Posts: 70
Accepted Answer
buckynwd wrote:
... the date in the 3rd form can't be more than 2 weeks from today....var DateTimeField1 = Num2Date(DateTimeField1, "MMM DD, YYYY")
var $ = Num2Date($, "MMM DD, YYYY")

if (OEDCode == "5" and HasValue($)) then
(Date2Num($ - DateTimeField1)) <= 14
else
$.rawValue = num2date(date(), DateFmt(2))
endif
As George pointed out, you can't use '$' as a variable since it is a reserved character. That aside, there is another error in the code:
"(Date2Num($ - DateTimeField1)) <= 14"
The character "<=" is used for comparison (like in an 'if' statement) and cannot be used in an assignment statement, so the entire code section will fail since the error will produce a null value.As a coding tip, it is often better to write out what you are trying to achieve in plain English, and then reduce each statement to pseudo-code, and finally to code. Looking at the code above, you need to nest a second IF statement in there!

"IF the OEDCode field contains '5' AND the current field has a value, THEN
IF the current field, minus the value of DateTimeField1 is NOT less than or equal to 14 THEN
The current field gets a value equal to today's date.
ENDIF
ENDIF"

Compare the psuedo-code to your code above and you should quickly see the answer that you need :)

Hope that helps!

DaveyB

LiveCycle Designer 8.0
"Genius is one percent inspiration, ninety-nine percent perspiration." ~~ Thomas Edison
"If at first you don't succeed, get a bigger hammer." ~~ Alan Lewis
"If the conventional doesn't work, try the unconventional" ~~ DaveyB