Resolution of Variables
Variables are generally resolved when executing eScripts or, for example, during an internal program flow.
The following rules apply:
- Every variable between percent signs is replaced by its current value (%Name% is therefore replaced by the value of the Name variable).
Example:
%ServerProperties.NetInstallDir% is replaced by the value of the respective setting DSM share on the depot, i.e. \\DSMServer\DSM$\ - An “empty“ variable is replaced by a percent sign.
Example:
%% is replaced by % - If the value of a variable contains another variable, the other variable will also be resolved. This process is repeated until there is no variable left.
Example:
If the value of the setting DSM share on the depot in the example above is \\%CurrentServer%\DSM$\ and %CurrentServer% is DSMServerMain, the variables are resolved in the following manner:
%ServerProperties.NetInstallDir% is resolved to \\%CurrentServer%\DSM$\
\\%CurrentServer%\DSM$\ is resolved to \\DSMServerMain\DSM$\
Using Brackets with Variables
The rules above imply that a pair of two percent signs are generally interpreted as a variable; independent of the characters between the percent signs.
Therefore it is not possible to enter another variable directly in an existing variable.
Example:
An eScript contains the variables %DSMServer1%, %DSMServer2% etc. and %Number%.
In the following process, the system uses the variable %DSMServer%Number%%.
According to the logic explained above, the system would find the variables %DSMServer%Number%% and %% for resolution in the variable %DSMServer%. Since %DSMServer% does not exist as a variable in this case, the variable cannot be resolved.
The following requirement should be met instead: first, to resolve the %Number% variable to the value 1, for example, and then to resolve the resulting variable %DSMServer1%.
There are two solutions for meeting this requirement:
- Defining variables and auxiliary variables separately before employment:
Set (Number,1)
Set (DSMServerNumber,%%DSMServer%Number%%%) (after being resolved, the variable has the value %DSMServer1%)
.....
.....%DSMServerNumber%..... - Using brackets:
.....
.....%[DSMServer%Number%]%..... (after being resolved, the variable also has the value %DSMServer1%)
If you use brackets, the variable in brackets is resolved first; then, the resulting variable is resolved.
Using this syntax helps you avoid defining auxiliary variables (this process is less complex).
Backslashes in Variable Values
When the value of a variable is interpreted, DSM eliminates the trailing backslash "\". This prevents double backslashes from appearing in paths.
Example:
Use the following path defined with the variable _Userdirectory: %Userdirectory%\TEST.
If you assign _Userdirectory the value C:\WINNT\User\, NetInstall interprets the path as follows: C:\WINNT\User\TEST, , which does not work for: C:\WINNT\User\\TEST.
Checking and Resolving Variables During Resolution
You can specify alternative values for variables that cannot be resolved as required.
There are two cases in which DSM supports using alternative values:
- if a variable cannot be be resolved in general
- if a variable is not an integer
The syntax in the first case is: %[~<variable>~<alternative value>]%
This means that if the specified <variable> cannot be resolved, the specified <alternative value> is used.
Examples:
%[~CurrentComputer.Var.Settings.Value~1]%
If the specified DSM variable is not set, the alternative value 1 is used.
%[~ProgramData~C:\ProgramData]%
If the environment variable ProgramData is not available on a computer, the alternative value is used instead.
The syntax in the second case is: %[~(int)<variable>~<alternative value>]%
This means that if the specified <variable> is not an integer after resolution, the specified <alternative value> is used.
Examples:
%[~(int)FreeSpace~0]%
This ensures that there is another number available for calculation after resolving the variable.
%[=1 max %[~(int)percent~50]% min 100]%
This ensures that there is a number between 1 and 100 available after resolving the variable; if the number is not valid, 50 is used.