Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Unable to Resolve Script Error Message

Avatar

Level 1
Hi,



I am using Windows Vista and Acrobat Adobe Extended Version 9.



I am struggling with a script. I am sure it is something simple; however, I am struggling mightily with it. I am getting an error message, shown below, that I am unable to understand and resolve.



I am trying to calculate age when given a birthdate. I used "Search" to find a script here at Adobe forums.



Here's the script that I am using:



//
StoneG, "Third Time Lucky to get Age from DOB entry" #1, 24 Oct 2006 7:21 am

// Jared Langdon

// J. Langdon Consulting

// www.jlangdon.ca



// DOB = Date of Birth



var strDOBYear = Birthdate.rawValue.substr(6,4);

var strDOBMonth = Birthdate.rawValue.substr(0,2);

var strDOBDay = Birthdate.rawValue.substr(3,2);

var oDOB = new Date(parseInt(strDOBYear,10), parseInt(strDOBMonth,10)-1, parseInt(strDOBDay,10) );

var oToday = new Date();



// determine whether the person's birthday has already occurred this year

var bBirthdayHasOccurred = false;

if (oDOB.getMonth() < oToday.getMonth()) bBirthdayHasOccurred = true; if ((oDOB.getMonth() == oToday.getMonth()) && (oDOB.getDate() <= oToday.getDate())) bBirthdayHasOccurred = true;



var nCurrentAge = 0;

if (bBirthdayHasOccurred)

nCurrentAge = oToday.getFullYear() - oDOB.getFullYear();

else

nCurrentAge = oToday.getFullYear() - oDOB.getFullYear() - 1;

this.rawValue = nCurrentAge;



==========



I changed the script slightly. I changed from:



var strDOBYear = DateOfBirth.rawValue.substr(6,4);

to

var strDOBYear = Birthdate.rawValue.substr(6,4);



My variable is "Birthdate".



And I changed boolBirthdayHasOccurred to bBirthdayHasOccurred.



Upon opening the file in Acrobat 9, my error messages is as follows:



Acrobat JavaScript Debugger Functions Version 9.0

Acrobat EScript Built-in Functions Version 9.0

Acrobat Annotations / Collaboration Built-in Functions Version 9.0

Acrobat Annotations / Collaboration Built-in Wizard Functions Version 9.0

Acrobat SOAP 9.0



Birthdate.rawValue has no properties

8:XFA:form1[0]:#subform[0]:Age[0]:calculate



The line above repeats several times. And then...



boolBirthdayHasOccurred is not defined

19:XFA:form1[0]:#subform[0]:Age[0]:calculate

boolBirthdayHasOccurred is not defined

19:XFA:form1[0]:#subform[0]:Age[0]:calculate

Birthdate.rawValue has no properties

8:XFA:form1[0]:#subform[0]:Age[0]:calculate

Birthdate.rawValue has no properties



I have no idea why it mentions "boolBirthdayHasOccurred" because that text is not even present. The last two lines repeat more several times.



When I have delete this entire script, the problems disappears. I have tried finding "boolBirthdayHasOccurred" without success.



Can someone point me in the right direction to troubleshoot this problem?



Regards,

Kevin
5 Replies

Avatar

Former Community Member
Kevin,



Create a Date/Time field and call it 'dob'. Add the display pattern 'date{MM-DD-YYYY}'.



Create a TextField field and call it 'age'.



On the 'dob' exit event add the following FormCalc script to execute on the Client.



age = Round((Date2Num(dob.formattedValue,"MM-DD-YYYY")-Date())/365.25)*-1



Steve

Avatar

Level 1
Hi Steve,



That works very well. Thank you!



Aside from your above response and out of curiosity, when performing calculations or manipulations on a "Date/Time" field, what does Adobe assume for the format of the "Date/Time" field?



Yesterday while trying to solve my issue, I discovered that the "Date/Time" field format appeared to be different the Display, Edit, Validation and Data formats. It appeared to be YYYY-MM-DD, which is different than my assigned Display, Edit, Validation and Data formats.



Again, thank you Steve for your assistance.



Regards,

Kevin

Avatar

Former Community Member
The default woudl be the format that your machine has set.

Avatar

Level 1
Hi Paul,



>>The default would be the format that your machine has set.



That's interesting. So the users' machines are very likely different than mine. So there's no way of knowing in advance. That would seem to make the routine suggested by Jared Langdon (see my top post in this thread) somewhat troublesome? If users' machines are set differently than his, then his routine wouldn't work?



I learned two important items with this task:



1) I need to somehow specify (as done by Stephen) the format of the date numbers before I use them;



2) Rather than using the Calculation Event on the Age, I should instead use Exit Event on the Date-of-Birth field.



Thank you for your response.



Regards,

Kevin

Avatar

Level 2
I found a problem with the script provided by SL Walker.



age = Round((Date2Num(dob.formattedValue,"MM-DD-YYYY")-Date())/365.25)*-1



when I enter a dob of 03/01/1980 then age = 29, and when I enter a dob of 04/01/1980 then age = 29, but that is incorrect b/c their bday has not occured for the present year so the age is actually 28 until 04/01/1980.



I do not know the solution to fix this but if anyone else does I would appreciate the help!