Variable - Create
Declaration
<AMVARIABLE NAME="text" VALUE="text"/"text (encrypted)" DESCRIPTION="text" TYPE="text (options)" READONLY="YES/NO" PRIVATE="YES/NO" ISPARAMETER="YES/NO" SECURE="YES/NO" />
Overview
Creates an Automate Desktop variable, which is used to store dynamic values for use in subsequent steps. The value of a variable is specified at runtime by placing the variable name in percent signs (for example, %myvarname% automatically converts to its value at runtime). For more information, see Variables.
Practical usage
Variables must first be created to use them in a task. This activity is ideally used in the beginning steps of a task to create one or more required variables for subsequent steps to reference them during runtime. After a variable is created, its contents can be viewed, set, or modified within any step parameter.
General
| Property | Type | Required | Default | Markup | Description |
|---|---|---|---|---|---|
| Variable name | Text | Yes | (Empty) | NAME="theVarName" | The name of the variable to create. Variable names are not case sensitive, however, they must contain only alphanumeric characters, start with a letter, and cannot contain spaces. It is good practice to select a name that is descriptive of what the variable holds. For example, if a variable holds the size of a shoe, name it ShoeSize or theSize. It is important that this value is unique, descriptive, and does not conflict with any BASIC scripting keywords (examples of names that can cause a conflict include: date, day, or week, and so on). |
| Initial value | Text | No | (Empty) | VALUE="theVariable" | The value the variable is set to initially. As with all parameters, this value can be literal or an expression if it is surrounded by percent signs (%). |
| Description (optional) | Text | No | (Empty) | DESCRIPTION="theDescription" | An optional text description that describes the purpose of the variable. This information is displayed in visual mode time in the Debug window of the Task Builder under the Variables tab. |
Advanced
| Property | Type | Required | Default | Markup | Description |
|---|---|---|---|---|---|
| Variable type | Text (options) | No | Auto |
|
Specifies the variable type to associate with the value.
The available options
are:
NOTE: Arithmetic operation between various types of variables is not allowed if at least one variable contains a non-numeric character. |
| Variable is read-only | Yes/No | No | No | READONLY="YES" | If selected, specifies the variable cannot be set to a value other than value specified in the Initial value parameter. Selecting this option is equivalent to creating a task specific constant. This parameter is disabled by default. |
| Variable is private | Yes/No | No | No | PRIVATE="yes" | If selected, specifies the variable is only available to the current (or parent) task and not to any subtasks (or child tasks) that were started with the Task - Start subtask activity. If this value is disabled, the variable is available to subtasks. This parameter is disabled by default. |
| Treat as parameter | Yes/No | No | No | ISPARAMETER="YES" | If selected, specifies the variable is only created if it does not already exist. This is useful when a task has parameters passed to it at runtime (that is, variables of the same name are created automatically), but a default value is assumed when debugging and parameters are not present. This parameter is disabled by default. |
| Variable is secure | Yes/No | No | No | SECURE="YES" | If selected, the variable is encrypted and the contents of the Initial value parameter are not displayed in the Steps pane of the Task Builder or on the Action Properties screen. This parameter is disabled by default. NOTE: Copying/pasting a secured value step from one task to another is not supported and omits the contents of the Initial value parameter. |
Additional notes
Using variables
All variables must be created using the Variable - Create activity before they can be used. After they are created, variables can be set using the Variable Set activity, or by certain actions that support populating variables. To get data out of the variables in any action parameter, simply surround the variable name with percent signs (%) (for example, %varname%). Do not use percent signs when specifying the name of a variable to populate, percent signs (%) are only needed to get data out.
Examples
- Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
- To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.
Example 1
The following sample task creates a variable named theSampleVariable with the value of Hello world! which is displayed in a dialog.
<AMVARIABLE NAME="theSampleVariable">Hello world!</AMVARIABLE>
<AMSHOWDIALOG>Variable Value - %theSampleVariable%</AMSHOWDIALOG>
Example 2
The following sample task displays how variables can be used interactively. A selection dialog is displayed, allowing the user to select one or more list items. After the user selects one or more items (or no items) and clicks OK, a second dialog is displayed, listing the selected items.
<AMVARIABLE NAME="var1">First Name</AMVARIABLE>
<AMVARIABLE NAME="var2">Last Name</AMVARIABLE>
<AMVARIABLE NAME="var3">Address</AMVARIABLE>
<AMVARIABLE NAME="var4">Phone Number</AMVARIABLE>
<AMVARIABLE NAME="theVars" />
<AMSHOWDIALOG ACTIVITY="select" MESSAGETEXT="Please select one or more items below." RESULTVARIABLE="theVars" LISTTYPE="checkbox" ITEMS="%var1%,%var2%,%var3%,%var4%" VALUES="First Name,Last Name,Address ,Phone" WINDOWTITLE="Sample Item Selection Task " ONCANCEL="stop" FORCESELECT="NO" MULTIPLE="YES" />
<AMSHOWDIALOG WINDOWTITLE="Selected Items" BUTTONS="ok_cancel" ONSECONDBUTTONCLICK="stop">You selected the following items:%theVars%</AMSHOWDIALOG>