About Custom Code and Variables

InstallAnywhere 2017

Custom Code can both get and set InstallAnywhere variables. This ability can be useful in two cases:

A project can set InstallAnywhere variables, which can be used as parameters for Custom Code. For example, if a Custom Code Action is designed to know the directory to which the end user was installing, use the Set InstallAnywhere variable action to set PARAM_1 to $USER_INSTALL_DIR$. Then, in the Custom Code Action, call InstallerProxy.substitute("$PARAM_1$") to determine its value.
InstallAnywhere variables may also be used to store return values from Custom Code Actions. These variables can be queried by other actions or rules. To do this, call the method InstallerProxy.setVariable("PARAM_1",<OBJECT>) to set the InstallAnywhere variable’s value. Remember that these variables are treated as strings, and will have java.lang.Object.toString() called upon them to determine their value in InstallAnywhere. Once PARAM_1 has been set it can be accessed in the normal way, using $PARAM_1$ in a later InstallAnywhere rule or action.

A common problem when accessing the values of InstallAnywhere variables from within custom code is the improper use of the getVariable() and substitute() methods. The most common problem is the use of getVariable() on a magic folder object (for instance, $USER_INSTALL_DIR$) and then trying to cast this object to a string. Instead, use substitute(), which will resolve the contents of the variable to a string, instead of casting the object.

Note • When each method in a custom action or plug-in is invoked, it will not have access to any argument (InstallAnywhere) variables specified if they are implemented as a plug-in (those set in the plug-in customizer). If the variables are implemented as a custom code action, any InstallAnywhere variables the method uses need to be set and finalized in the previous phase of the installation (or externally for a dynamic InstallAnywhere merge module).

Note • For information on variables, see Variables.

See Also