Read and Review Automation Anywhere Documentation

Automation Anywhere Version 11.3

Close Contents

Contents

Open Contents

Assigning Variables in a Task

  • Updated: 5/07/2020
    • 11.3.x
    • Explore
    • Enterprise

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:

  1. In the Workbench, drag the Variable Operation command into the task.
  2. Select the User Variables option.
  3. 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.
  4. Select the Assign operation radio button.
  5. 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:

  1. In the Workbench, drag the Variable Operation command into the task.
  2. Select the User Variables option.
  3. 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.
  4. Select the Assign operation radio button.
  5. For the list variable, the "Select Position" is displayed. Specify the position for this value. For example, $Counter$
  6. You can also specify another variable to be inserted here by pressing the F2 function key and selecting the variable.
  7. 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.

  1. In the Workbench, drag the Variable Operation command into the task.
  2. Select the User Variables option.
  3. 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.
  4. Select the Assign operation radio button.
  5. 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".
  6. You can also specify other variables to be inserted here by pressing the F2 function key and selecting the variable.
  7. 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.

  1. Comment: This Loop will execute for 5 times as List read from text file variable has 5 entries.
  2. Comment: Create Variable List Type : Source = Read from text file having this RDlsttxt = 11, 21,31,41,51
    Start Loop "List Variable
    $RDlsttxt$"
  3. 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

  1. Comment: We use an array variable to read from existing excel file
    Connect to "$ConnectStr$"
    Session:'Default'
  2. Comment: ArrayRows is a system defined variable used to retrieve total rows in the user defined array.
  3. 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
  4. 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)$')' Session:
    'Default'
    End Loop
    Open "http://www.ebay.com/"
  5. Comment: Extracting the books on the philosophy into a CSV file using Web Recorder
    Set text 'philosophy books' into _nkw in the
    webpage 'Electronics, Cars, Fashion, Collectibles, Coupons and More
    Online Shopping | eBay'
    Click on 'Search' Command Button in the
    webpage 'Electronics, Cars, Fashion, Collectibles, Coupons and More
    Online Shopping | eBay'
    Loop While Web Control Exists (Other HTML
    Control : Next ) in the webpage 'philosophy books |
    eBay'
    Extract Multiple Data from Webpage to
    $filePath$ from the web page: philosophy books | eBay
    Click on 'Next' Other HTML Control in the
    webpage 'philosophy books | eBay'
    End Loop
    Extract Multiple Data from Webpage to
    $filePath$ from the web page: philosophy books | eBay
Send Feedback