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

Is it possible to create the following Date Script?

Tech264
Registered: Apr 4 2008
Posts: 111
Answered

I have two of the same forms that I have to put on the intranet for employees except one of them has modifications that the other does not have. There's a date field called Date of Admission on the form and what I want to do is that the new form can only be completed if the date of admission is either on or after 07/01/2009. So if they enter a date that's equal or after 07/01/2009 they can use the form. If they enter a date prior to that date I would like a pop-up box that tells them they can't use that form because it's prior to said said.

I will also add the code to the old form as well that if they enter a date after 07/01/2009 they can't use it.

I don't know of that's a Formcalc or a Javascript I need to put in there.

ie. Sorry you can't use this form Date of Admission must be on or after 07/01/2009, Try the old one instead.

Thanks!

My Product Information:
LiveCycle Designer, Windows
suewhitehead
Registered: Jun 3 2008
Posts: 232
I think I would do it like this:
For Date Of Admission, make these fields: "Month" "Date" "Year".
Put all other fields on a subform named MainFields.
Make MainFields subform Hidden when form opens.
Put script on both Month and/or Year fields with IF statement about month and year like this: (fill in the correct javascript to do each of these parts)
if((the month is July, August, September, October, November, or December) && (year >=2009))
{
MainFields.presence = "visible"
}
else
{MainFields.presence = "hidden"
var cResponse = app.alert({
cMsg: "Sorry, you cannot use this form. Please use form xxxxx instead.",
nIcon: 2, nType: 2,
cTitle: "Wrong Form"})
}

I will leave the exact javascript to you. This is only a general direction in which to go.

You could also make the MainFields subform fields all read-only instead of Hidden.
Tech264
Registered: Apr 4 2008
Posts: 111
This is kind of confusing since I'm not trying to hide any forms. I just wanted a popup box alerting the person entering data that when they get to the AdmissionDate field that it has to be after a certain date.

Something like:

If DOA <= "07/01/2009"
then msg: "You cannot use this form must before after 07/01/2009"

that's it.

I don't know if it's suppose to be at the Enter or MouseEnter prompt.
Tech264
Registered: Apr 4 2008
Posts: 111
I made a slight modification to the code provided and I checked it with the syntax checker and all seemed fine but it doesn't work on the form.

Here's a picture of the screen.

http://narcofreedom.com/forms/datehelp.jpg

[img]http://narcofreedom.com/forms/datehelp.jpg[/img]
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Thom's article shows in general what has to be done to process a date in AcroForms or LiveCycle Designer. Since date stings can come in all sorts of string values, one needs to convert the date string to a common standard. For example January 2, 1900 can be written as 'Jan 2, 1900', '2 Jan 1900', '01/02/1900', '02/01/1900', etc, so one can not just compare the character string for the date. But if one converts the date to a number from a given date like January 1, 1900, then January 2, 1900 becomes '2' and January 31, 1900 is '31'. And as long as the character strings are converted to a number from the same starting date, Epoch date, one can compare the numbers.

LiveCycle Designer provides the FormCalc function 'Date2Num()' to convert a date strings to the number of days from the Epoch date. And also has the 'Num2Date()' function to convert the number of days from the Epoch date to a formatted character string. Note one may need to provide the character string format for the dates. Once one gets the number of days since the Epoch date, comparisons and calculations are now possible.

So if one has a field called 'DOA' with a date formatted value of 'MM/DD/YYYY' one can use the following script as an 'exit' event for the 'DOA' field to compare and issue a message based on the values of the DOA date string and the test date string.
// get the number of days since the epoch date for the DOA datevar fDOA = Date2Num(DOA.formattedValue, "MM/DD/YYYY")// convert test date to number of days since epoch datevar sTestDate = "07/01/2009"var fTestDate = Date2Num(sTestDate, "MM/DD/YYYY")// compare the datesif (fDOA <= fTestDate) then// build message stringxfa.host.messageBox(Concat("You cannot use this form until after ", sTestDate) )endif

George Kaiser

Tech264
Registered: Apr 4 2008
Posts: 111
Thank you GKaiserel, that worked fine. Before you responded I had tried the following code which seemed to work but the alert box popped up no matter what date I had in there.

if(DOA.rawValue > 07/01/2009) then
xfa.host.messageBox("Sorry, you cannot use this form! Must be before 07/01/2009.")
$.rawValue = ""
// to set focus to the DOA field so that the user can type his
new value..
xfa.host.setFocus(this.DOA)
endif
endif