You can create field variables in Events. For example, you can assign the global variable
$countryCode to the field
CountryCode. You can also create global variables in scripts.
In this example, the global variables $amount1 and
$amount2 are created as field variables in an Event. The global variable
$total in this script calculates the sum of
$amount1 and
$amount2.
In this example, the global variables $firstName and
$surName are created as field variables in an Event. The global variable
$fullName in this script concatenates the strings
$firstName and
$surName.
In this example, the global variable $name = “Mr Mike Jones” is used as input to create the global variables
$nameSur (should contain “Jones”) and
$nameFirst (should contain “Mike”).
The global variable $name is a string variable containing 13 characters. The string and position of the characters are shown in the table below.
The global variable $nameSur is a substring of
$name, starting with the character in position 9 (J) and ending with the last character in the string (s):
The global variable $namefirst is a substring of
$name, starting with the character in position 4 (M) and is four characters long:
A global variable name can consist of letters (A-Z, a-z), digits (
0-9) and underscore (
_). The name must begin with a letter or underscore.
You can create global variables ($<variable name>) for any field in an Event. For example, if the Event contains the field
countryCode, you can create a field variable called
$countryCode. When the data is processed,
$countryCode will get the current value of the field
countryCode. The field variable can be used in scripts as well as in the Design Center formatting tools.
Note that creating field variables affects performance, so you should only create field variables when necessary. If you only need to retrieve the field value in a script, you can use field references instead. See
Field references.
To use a global variable in a numerical expression, or as an argument to a function that expects a numeric argument, you must convert the string type to a numerical value, which affects performance.
To re-use a global variable within the scope of a job, you must first assign a value to the variable, or clear it, which are tasks that could introduce errors to your Project.
When you import a function file to your Project, the variables used within the function becomes part of the global scope. This introduces a risk that they interfere with variables used in existing scripts. Thus the portability of function files is limited.