Variable - Set

Declaration

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

Related Topics   

Overview

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. After a variable is created, its contents can be displayed at runtime by enclosing the variable name in percent signs (%) (for example, %myvarname% automatically converts the contents at runtime). This activity is mainly used to add a new value or change the current  value of an existing variable created in 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 can 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. After they are created, variables can be set using the Set variable activity or by certain actions that support populating variables. To extract data from the variables in any action parameter, enclose the variable name in 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 extract data.

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

The following 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

The following 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>