Variables

You can define form variables in Designer to store specific information in a central, accessible location. A variable typically acts as a placeholder for text that you might have to change in the future. Form variables in Designer are always of the type "string". For example, a variable can store the text of a message box title. When the text needs to change, all you have to do is open the affected form or template and update the text once through the variable definition. Designer automatically propagates the new text across all instances of the inserted variable.

Keep in mind that form variables are defined outside of the Script Editor, and are accessible by scripts on all objects on a form, as opposed to scripting variables that you create in a specific FormCalc or JavaScript script.

You can create, view, and delete variables without using scripting. However, you must use scripting to access the values stored by variables and manipulate them, or to apply the values to objects on your form.

Note: Form variable values reset each time you open a form.

Before you create a variable, decide the name of the variable and the text that it will contain. Variable definitions are saved with the form or template.

Naming variables

At run time, naming conflicts occur when the names of variables are identical to those used as XML Form Object Model properties, methods, or form design field names. These conflicts can cause scripts to return unexpected values; therefore, it is important to give each variable a unique name. Here a couple of examples:

  • Use the variable name fieldWidth and fieldHeight instead of x and y .

  • Use the form design object name clientName instead of name .

    Note: Variable names are case-sensitive and should not contain spaces.

To define a text variable

  1. Select File > Form Properties.

  2. In the Variables tab, click New (Insert) .

  3. In the Variables list, type a unique name for the variable and press Enter. Variable names are case-sensitive and should not contain spaces.

  4. Click once in the box to the right and type the text you want to associate with the variable.

    The variable appears in the Hierarchy palette at the form level.

    View full size graphic
    A. New form variable

To view a text variable definition

  1. Select File > Form Properties.

  2. Click the Variables tab and select the variable from the Variables list. The associated text is displayed in the box to the right.

To delete a text variable

  1. Select File > Form Properties.

  2. In the Variables tab, select the variable and click Delete (Delete)  .

Using variables in calculations and scripts

After you have created form variables, you only need to reference the variable name in your calculations and scripts in order to obtain the value of the variable.

Important: When naming variables, you should avoid using names that are identical to the names of any XML Form Object Model properties, methods, or object names.

For information about XML Form Object Model properties, methods, and objects, see the Scripting Reference.

For example, create the following form variable definitions.

Variable name

Value

firstName

Tony

lastName

Blue

age

32

In FormCalc, you can access the variable values in the same manner that you access field and object values. In this example, the values are assigned to three separate fields:

    TextField1 = firstName 
    TextField2 = lastName 
    NumericField1 = age

You can also use variables in FormCalc functions in the same way, as shown in this example:

Concat( "Dear ", firstName, lastName )

In JavaScript, you reference variable values by using the .value property instead of the .rawValue property that is used for field and object values, as shown in this example:

TextField1.rawValue = firstName.value;

Note: Using and modifiying form variables with scripting in XFA forms can cause the document message bar in Acrobat and Adobe Reader to display a signature validation status warning indicating that the signature validity is unknown due to subsequent changes to the document.

// Ethnio survey code removed