Expand my Community achievements bar.

SOLVED

Declared variables in Script Object are being redeclared

Avatar

Level 8

I am facing very strange behaviour when declaring local variables in Script Object under the main form (form1), as well as under an inner subform.

I have used this method always, and it works like a charm. I declare a variable in a script object, and initialize it using an initialization function as follows:

//Script Object "scTest"

var testVar;

function initialize() {

  testVar = "New value";

}

function printTestVar() {

  console.println("testVar = " + testVar);

}

Then, in the init event of some element in the main form, I call the function as follows:

scTest.Initialize();

Then later, any reference to this variable "testVar" will have the value "New Value". For example, if I call the function "printTestVar()" on a click of a button it will print "New Value".

I created the sample PDF attached in the link below. This file works as it should. However, I have one legacy form that is not working is such. It seems only this legacy form has this problem, and I am unable to find out why. Basically, some time, when the I call the function "printTestVar()" the variable declaration is executed again, and the value of "testVar" will become "undefined". Unfortunately, I cannot send this form for testing by others.

I am wondering if anyone has faced this problem and how to troubleshoot what is going on.

Variables in Script Object.pdf

1 Accepted Solution

Avatar

Correct answer by
Level 8

After some research and troubleshooting, I found out that I have to comment out the line below in XML View:

   <!-- <?originalXFAVersion http://www.xfa.org/schema/xfa-template/2.8/ v2.7-scripting:1?> -->

Then, the problem just disappeared !!!!

I hope this will be of help to others.

Tarek

View solution in original post

1 Reply

Avatar

Correct answer by
Level 8

After some research and troubleshooting, I found out that I have to comment out the line below in XML View:

   <!-- <?originalXFAVersion http://www.xfa.org/schema/xfa-template/2.8/ v2.7-scripting:1?> -->

Then, the problem just disappeared !!!!

I hope this will be of help to others.

Tarek