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

Global Variables

krm240
Registered: Apr 17 2009
Posts: 95

Does LC support global variables?
 
I wish to declare a few globals values at form initialization and refer to the values in other functions.
 
Is this possible?
If so, what is the syntax to declare such a variable?
  

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The answer is "Sort Of". I'm assuming that you mean Document Global, not application global?

There's no official global variable spec for XFA forms, but there are several ways to store data withing a document context so that it can be used by scripts throughout the document.

First, don't try using a "Scripting Object". The code in a scripting object may be re-executed at any time.

Here's a list of techniques:

1. Create a top level hidden field and store the data here. If the field is bound to the data model then the data will be available the next time the form is opened.
2. Attach the variable to a node in the XFA object structure, for example the top level form node.
Like this: xfa.form.Form1.myData = "Hello World";

This method may not be entirely reliable since Acrobat can recreate the object structure at any time, although no necessarily likely.

3. Use the old AcroForm Document object. This one is my favorite, and besides using a form field it's the most reliable:

Like this: event.target.myData = "Hello World";

4. Use the global object. This one is also very reliable.
Like this: global.myData = "Hello World";

5. Store the data in an application level object, almost any object will work. This one works great in older versions of Acrobat, but might have problems with newer versions.

Like this: app.media.myData = "Hello World";


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