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

Completely stuck with '... is not a function' error message

Lea1337
Registered: Jul 14 2009
Posts: 64
Answered

I am currently completely stuck with the debugger error message 'Employee.empvalidity() is not a function', and I have checked everything I could think of. This makes my entire form not work, and if I "remove" this function, the debugger jumps straight to the next function and reports that it too is not a function. I'm therefore suspecting that if I find the error, it will be solved for "all" the functions.

The form has worked fine previously with the function(s) I mentioned above, but I worked on the form a month ago or so, and must have (unfortunately) made some kind of change that I of course don't remember now, that ruined everything :-p

Ok, so to give a few details:
I have a radiobutton list 'EmpType' containing two radiobuttons. I also have a drop-down list (ActionDDList) and some JavaScript code that runs on the change event of the dd-list. It begins like this:

var actionvalue = form1.Main_subform.Caption_subform.ActionDDList.xfa.event.change;

if (actionvalue == "Competence Entry" || actionvalue == "New Employee" || actionvalue == "Internal Changes" || actionvalue == "Relocation" || actionvalue == "Resignation") {

var empcheck = Employee.empvalidity();
var loccheck = Employee.locationvalidity();
etc.....

The empvalidity() and locationvalidity() functions are located in a script object called Employee, the code for empvalidity() is like this:

function empvalidity() {
var emp = form1.Main_subform.Caption_subform.EmpType.rawValue;
if (emp == "1" || emp == "2") {
return true;
}
else {
xfa.host.messageBox("Please choose type of employee from the radio button list");
return false;
}
}

It's a simple function that only checks to see if the user has made a choice in the radiobutton list. As I mentioned before, this has worked perfectly before, so I guess the error is not to be found in the syntax of the code stated above..(?) But I would very much appreciate some hints as to where I can look for errors, as I'm completely lost and the debugger does not give me much help.. :-p

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The message is specifically complaining that the functions don't exist, so the problem lies with the code where the functions are defined, i.e, in the Employee object. The great likelyhood is that there is an error in this code which causes an exception. So the function definitions are never run.

Acrobat has the unfortunate characteristic of not reporting errors that occur in the execution of the XFA scripting objects. Give this code a good look over. If you can't spot the problem by eye then you'll need to force Acrobat to report the problem.

Go to the JavaScript preferences and turn the "When an exception is thrown" to "trace". This should make the exceptions more verbose. The place a couple of console.println() statments in the scripting object to get an idea of how far excution is getting. You can also place the whole scripting object in a try/catch block and report the exception with a console.println().

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I just tried putting the code in a scripting object into a try/catch block and it didn't work. And setting "When an exception is thrown" to "trace" didn't work either. It seems the only way to get a handle on an exception in a scripting object is with console.println() statements.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Lea1337
Registered: Jul 14 2009
Posts: 64
Thanks for the tip. I just tried putting console.println() a few places in my script, and got the following result:

I tried placing it as the first item under the empvalidity() function, in the simplest form:

function empvalidity() {
console.println("Testing something here");
var emp = form1.Main_subform.Caption_subform.EmpType.rawValue;
if (emp == "1" || emp == "2") {
return true;
}
else {
xfa.host.messageBox("Please choose type of employee from the radio button list");
return false;
}
}

It does not get posted in the JavaScript debugger. Which tells me that the empvalidity function is never run..? Which in turn means that the Javascript code that is supposed to run the empvalidity() function for some reason can't find the 'Employee' scripting object at all perhaps? But I don't know why, it looks to me like it's placed correctly in the hierarchy:

form1
(Master Pages)
Main_subform
{Variables}
Employee

Or..?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The problem is not with locating the Employee scripting object. If it were, then the console window would be reporting that "Employee" is undefined, instead of reporting that "empvalidity" is not a function.

Place the console.println() function above the function definition, not inside it. The code in the scripting object is run the first time it's referenced, and this is when you should see the console message. And it should only be run once. If there are any syntax errors in the code, those errors will not be reported. So you won't see the console message and none of the functions or variables in the scripting object will be defined. Which is what you are seeing now.

So here's a simple test to see if there are any syntax errors in the scripting object code. Copy all the code in the scripting object into the console window and run it. If there are errors, then you should see them reported.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Lea1337
Registered: Jul 14 2009
Posts: 64
I did as you said and copied all the code from the scripting object into the console window and ran it. It found a syntax error in a completely different function that I had started working on, but not finished. I wasn't aware that none of the functions would work as long as there is an error in one of them (regardless of being referenced or not). Thanks! :-)
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The code in the scripting object is run as a block, all at one time. So it all has to work. If you have unfinished code, just comment it out.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

AcrUmbi
Registered: Dec 2 2010
Posts: 18
Thank you very much. This is exactly what was happening to me! Good to know about the scripting object being executed as a whole and not each individual function on its own merits. Still, I did waste a lot of hours on this issue. Now I know I have a "feature" in one of the three or four functions.

Annoying how that works!