Assigning Variables in a Task
- Dernière mise à jour2020/05/07
Assigning Variables in a Task
After you define variables, you can perform operations on them within your automation tasks. Variable Operation command enables you to assign and reinitialize user variables.
Assignment means that a single value is attached to a variable. This operation enables the user to reuse the defined variables as the task runs.
Assignment can be performed on three types of variables: Value, List, and Array. For lists and arrays, the assignment is applied by specific positions within the list or array.
The following table shows the types and source (subtypes) of the user variables and if it supports the assignment operations on them.
Assigning Value Variables
To assign a value to a Value type variable, follow these steps:
- In the Workbench, drag the Variable Operation command into the task.
- Select the User Variables option.
- Under "Specify Variable," select the variable from the list of all user variables that are defined for the task. The variable type and source is displayed.
- Select the Assign operation radio button.
- In the "Specify value" field, enter a value or insert another variable by pressing the F2 function key.
The right side of the assignment can include any regular operation.
Example: singleval1 = ($var2$ + $var5$ - 10) / 5
Operators supported:(, ), /, *, +, -
Order of Operations: Parentheses take first precedence in order, with the operation inside them being evaluated from left to right.
Assigning List Variables
When assigning values to a List type variable, you need to specify the position for that value. Any previous value for that position will be overwritten.
To assign a value to a List type variable, follow these steps:
- In the Workbench, drag the Variable Operation command into the task.
- Select the User Variables option.
- Under "Specify Variable," select the variable from the list of all user variables that are defined for the task. The variable type and source is displayed.
- Select the Assign operation radio button.
- For the list variable, the "Select Position" is displayed. Specify the position for this value. For example, $Counter$
- You can also specify another variable to be inserted here by pressing the F2 function key and selecting the variable.
- In the "Specify value" field, enter a value or insert another variable by pressing the F2 function key.
Assigning Array Variables
When assigning values to an Array type variable, you need to specify the positions for the values. Any previous values for these positions will be overwritten.
The source of the array variable can be Excel or CSV files, a database, or a text file, depending on the type of variable you select from the list.
To assign values to an Array type variable, follow these steps:
In the below example we are assigning an array variable for position (2,2) from another variable defined in the task.
- In the Workbench, drag the Variable Operation command into the task.
- Select the User Variables option.
- Under "Specify Variable," select the variable from the list of all user variables that are defined for the task. The variable type and source is displayed.
- Select the Assign operation radio button.
- For the array variable, the "Select Position" fields for Row and Column are displayed. Specify the position for these values. For example, "Row 2 and Column 2".
- You can also specify other variables to be inserted here by pressing the F2 function key and selecting the variable.
- In the "Specify value" field, enter values or insert another variable by pressing the F2 function key.
Variable Operation: Rounding Values
When using the Variable Operation command in the Workbench, be aware that values are rounded.
For example, we use a Variable Operation command to assign the value '01.20' to a variable named Temp. The returning value in the message box will be 1.2, as the extra zeros before and after the value are removed.
Examples:
Example 1
Type: List, Source: Read from text example.
- Comment: This Loop will execute for 5 times as List read from text file variable has 5 entries.
- Comment: Create Variable List Type : Source = Read from text file having this
RDlsttxt = 11,
21,31,41,51
Start Loop "List Variable $RDlsttxt$"
- Comment: Message box will show the addition of list variable value with other
variable value.Here
$row$=10
Variable Operation: $RDlsttxt$ + $row$ To $Prompt-Assignment$ Message Box: "$Prompt-Assignment$" End Loop
Example 2
Type: Array Source: Read from Excel
- Comment: We use an array variable to read from existing excel
file
Connect to "$ConnectStr$" Session:'Default'
- Comment: ArrayRows is a system defined variable used to retrieve total rows in the user defined array.
- Comment: ArrayExl - is a user-defined array variable, using a source that is Read
from Excel file. In this example, we use a list of books and games having title and
cost, which is initialized in the Variable
Manager.
Variable Operation: $ArrayRows($ArrayExl$)$ To $Row$ Start Loop "$Row$" Times
- Comment: To skip the header title of the csv extracted from the website use below If
condition
If $Counter$ Equal To (=) "1" Then Continue End If
Execute SQL Statement: 'Insert into Ebaykids (BookTitle,cost) values ("$ArrayExl($Counter$,1)$",'$ArrayExl($Counter$,2)