Variable - Set

Declaration

<AMVARIABLE ACTIVITY="set" VARIABLENAME="text" VALUE="text" />

Related Topics   

Description

Changes the contents of an existing variable.

Practical usage

Variables are used as storage mechanism to store data while a task is running. For more information see Variables. Once a variable is created, its contents can be displayed at runtime by placing the variable name in percent signs (for example, %myvarname% will automatically be converted it it's contents at runtime). This activity is mainly used to add a new value or change the current  value of an existing variable which was created on a previous step.

Parameters

General

Property Type Required Default Markup Description
Variable name Text Yes (Empty) VARIABLENAME="thecurrentdate" The name of the variable to set. The variable must be created on a previous step with use of the Create Variable activity.
New value Text Yes (Empty) VALUE="The current date is %Now()%" The value to set for the variable. As with all parameters, this value may be literal or an expression (if surrounded by percent % signs).

Description

Error Causes

On Error

Additional notes

Using variables

All variables must be created before they can be used. This is done using the Create variable activity. Once created, variables can be set using the Set variable 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 uses a Set variable activity to change the initial value of an existing variable.

Copy
<AMVARIABLE NAME="myVariable" VALUE="Automate"></AMVARIABLE>
<AMSHOWDIALOG WINDOWTITLE="CURRENT VALUE">The current value of myVariable is:%myVariable%</AMSHOWDIALOG>
<AMVARIABLE ACTIVITY="set" VARIABLENAME="myVariable" VALUE="Business Process Automation" />
<AMSHOWDIALOG WINDOWTITLE="NEW VALUE">The new value of myVariable is:%myVariable%</AMSHOWDIALOG>

Example 2

This sample task uses a Set variable activity to populate a value into a variable created with no initial value.

Copy
<AMVARIABLE NAME="myVariable" VALUE="" />
<AMSHOWDIALOG WINDOWTITLE="CURRENT VALUE">The current value of myVariable is:%myVariable%</AMSHOWDIALOG>
<AMVARIABLE ACTIVITY="set" VARIABLENAME="myVariable" VALUE="Business Process Automation" />
<AMSHOWDIALOG WINDOWTITLE="NEW VALUE">The new value of myVariable is:%myVariable%</AMSHOWDIALOG>

Example 3

Variable multiplication - This sample task describes how to multiply the initial value of two variables using the Set variable activity and display the results in a message box.

Copy
<AMSHOWDIALOG>This task describes how to multiply the initial value of two variables using the‘Set Variable’ action and display the results in a message box. This action changes the contents of an already existing variable. As with all parameters, this valuemay be literal or an expression (if surrounded by percent signs). This will work with other calculations as well (for example, addition "+", subtraction "-", division "/").</AMSHOWDIALOG>
<AMVARIABLE NAME="var1" VALUE="30"></AMVARIABLE>
<AMVARIABLE NAME="var2" VALUE="10"></AMVARIABLE>
<AMVARIABLE NAME="var3" VALUE="" />
<AMVARIABLE ACTIVITY="set" VARIABLENAME="var3">%var1 * var2%</AMVARIABLE>
<AMSHOWDIALOG>%var1% multiplied by %var2% results is %var3%</AMSHOWDIALOG>