Siebel eScript Language Reference > Siebel eScript Language Overview > Siebel eScript Concepts >
Variables in Siebel eScript
A variable is an identifier to which data may be assigned. Variables are used to store and represent information in a script.
Variables may change their values, but literals may not. For example, if you want to display a name literally, you must use something like the following fragment multiple times:
TheApplication().RaiseErrorText("Aloysius Gloucestershire Merkowitzky");
But you could use a variable to make this task easier, as in the following:
var Name = "Aloysius Gloucestershire Merkowitzy";
The preceding method allows you to use shorter lines of code for display and to use the same lines of code repeatedly by changing the contents of the variable Name.
Variables in Siebel eScript may be either global or local. Global variables can be accessed and modified from any function associated with the Siebel object for which the variables have been declared. Local variables can be accessed only within the functions in which they are created, because their scope is local to that function.
Variables can also be shared across modules. A variable declared outside a function has scope global to the module. If you declare a local variable with the same name as a module variable, the module variable is not accessible.
NOTE: Siebel eScript variables declared outside of a particular function are global only to their object (the module in which they are declared), not across every object in the application.
There are no absolute rules that indicate when global or local variables should be used. It is generally easier to understand how local variables are used in a single function than how global variables are used throughout an entire module. Therefore, local variables facilitate modular code that is easier to debug and to alter and develop over time. Local variables also use fewer resources.
To declare a variable, use the var keyword. To make it local, declare it in a function.
A value may be assigned to a variable when it is declared:
var perfectNumber = 28;
In the following example,
a is global to its object because it was declared outside of a function. Typically you declare all global variables in a general declarations section. The variables
d are local because they are defined within functions.
var a = 1;
var b = 1;
var d = 3;
var c = 2
c may not be used in the
myFunction() function, because it is has not been defined within the scope of that function. The variable
d is used in the
myFunction() function and is explicitly passed as a parameter to
someFunction() as the parameter
The following lines show which variables are available to the two functions:
myfunction(): a, b, d
someFunction(): a, c, e