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" />

Related Topics   

Description

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 in order 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 in order for subsequent steps to reference them during runtime. Once 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, must 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, then 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 would cause a conflict include: date, day or week, etc.).
Initial value Text No (Empty) VALUE="theVariable" The value the variable is set to initially. As with all parameters, this value may be literal or an expression (if 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
  • TYPE="auto"
  • TYPE="text"
  • TYPE="number"
Specifies the variable type to associate with the value. The available options are:
  • Auto (default) - The variable automatically detects the type of characters it contains. The variable adapts to the proper type when possible, depending on the operation being performed.
  • Text - The variable is text-based and can contain letters, numbers and/or special characters.
  • Number - The variable is number-based and can only contain characters that represent a numeric value. For example, 1.000, 4, 1e2, 007.
NOTE: Arithmetic operations between text-based and number-based types will fail if the text-based variable does not contain characters that represent a numeric value.
Variable is read-only Yes/No No No READONLY="YES" If selected, specifies the variable cannot be set to a value other than what is 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 particularly useful when a task may have parameters passed to it at runtime (that is, variables of the same name are created automatically), but a default value should be 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.

Description

Error Causes

On Error

Additional notes

Using variables

All variables must be created using the Variable - Create activity before they can be used. Once 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 percentage % signs (for example, %varname%). Remember not to use percentage signs when specifying the name of a variable to populate, percentage signs are only needed to get data out.

Examples

NOTE:
  • 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

This sample task creates a variable named theSampleVariable with the value of "Hello world!" which is displayed in a dialog.

Copy
<AMVARIABLE NAME="theSampleVariable">Hello world!</AMVARIABLE>
<AMSHOWDIALOG>Variable Value - %theSampleVariable%</AMSHOWDIALOG>

Example 2

This sample task displays how variables can be used interactively. A selection dialog appears allowing the user to select one or more list items. After the user selects one or more items (or no items) and then clicks OK, a second dialog appears listing which items were selected.

Copy
<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>