Array Type Variables
- Última actualización2020/05/06
Array Type Variables
An array variable is a two-dimensional variable that holds multiple values in a table of rows and columns. Arrays are very powerful for creating staging areas for data that need to be retrieved by your process as it runs.
When/Why To Use an Array Type Variable
Common uses of array variables include:
- Extracting data from web pages
- Extracting many rows of data from an Excel spreadsheet or a database
- Read or write data from/to a legacy system, an ERP system, or another application
- Filling out order forms with different fields from Excel to Database
The values can represent either text or numeric data.
After you create the variable, you can use it by inserting the variable in several of the Workbench commands.
When the value of the variable is modified, this value is reflected in any subsequent commands that are run by the task.
How to Create an Array Type Variable
You can create an array type variable in four ways:
Direct Assignment
Create an array type variable using direct assignment when you want the values of the variable to be defined directly to the variable.
To create an array type variable using direct assignment, follow these steps:
- In the Workbench, click the Variable Manager tab on the right side.
- Click the Add button. The 'Add Variable' window is displayed, with the 'Create New Variable' option selected.
- Select type 'Array'.
- Enter a name for the variable. The name must begin with an alphabet and should not contain spaces.
- Select how you want the array to be created. Default selection is 'Value' which indicates that you will define the values of this variable directly in it.
-
Specify the number of rows and columns in the field provided. Default values are 1 X 1.
-
Click the Initialize Values button. The Array Value Details window is displayed based on the rows and columns provided in step 6.
- Enter the values for each cell.
- Click the Save button to save the values.
- Click the Save button again to save the array variable.
You can modify the array dimensions using the Add Row, Add Column, Delete Row, and Delete Column buttons.
After the variable is saved, it is displayed in the Local Variables section of the Variable Manager.
Text File Assignment
Create an array type variable using text file assignment when you want to read values from a specified text file into the array variable while the task is running. The text file is used to define the array variable.
To create an array type variable using text file assignment, follow these steps:
- Determine the text file that you will use for assigning values.
-
- For Rows enter the data in a new line.
- For Columns use comma separated values.
-
Example: sports_team.txt
- In the Workbench, click the Variable Manager tab on the right side.
- Click the Add button. The 'Add Variable' window is displayed, with the 'Create New Variable' option selected.
- Select type 'Array'.
- Enter a name for the variable. The name must begin with an alphabet character and should not contain spaces.
- Select 'Read from text file' from the dropdown.
- In the Select File field, browse to the file or type the file path for the required text file. Use the Open File button to view the selected text file or to modify it.
- Click Save.
After the variable is saved, it is displayed in the Local Variables section of the Variable Manager.
Excel or CSV File Assignment
The Automation Anywhere Web Recorder and Excel commands extract data to Excel and CSV formats. You can use these files to create an array variable that might be used for entering or manipulating data for computing or analysis.
Automation Anywhere provides a range of options for retrieving subsets or partial sections of the data.
Create an array type variable using an Excel or CSV file assignment when you want the values of the variable to be retrieved from an Excel or CSV file.
To create an array type variable using Excel or CSV file assignment, follow these steps:
- In the Workbench, click the Variable Manager tab on the right side.
- Click the Add button. The 'Add Variable' window is displayed, with the 'Create New Variable' option selected.
- Select type 'Array'.
- Enter a name for the variable. The name must begin with an alphabet and should not contain spaces.
- Select 'Read from Excel/CSV file'from the dropdown.
- Browse and select the required file.
- Select the options you want for reading values from specific locations in the file.
You can choose from:
- All cells
- Entire Row
- Entire Column
- Range
Note: If you select Range, specify the From and To. You can use the Open File button to view the selected text file or to modify it. - Click Save.
After the variable is saved, it is displayed in the Local Variables section of the Variable Manager.
Database Assignment
You can define an array variable with values derived from the result of a database query. The array variable is created with dimensions that are determined as a result of running the query.
To create an array type variable using a database query, follow these steps:
- In the Workbench, click the Variable Manager tab on the right side.
- Click the Add button. The 'Add Variable' window is displayed, with the 'Create New Variable' option selected.
- Select type 'Array'.
- Enter a name for the variable. The name must begin with an alphabet and should not contain spaces.
- Select the 'Read from database' from the dropdown.
- Specify the database connection string details using Browse.Clicking on browse opens the Data Link properties dialogue box. Use it to test and create a valid connection string for the database of your choice.
- Enter Select Query by typing the entire database query.
- Click Save.
After the variable is saved, it is displayed in the Local Variables section of the Variable Manager.
Once you have created array variables by reading data from various sources, use Loop command to easily process them in your automation task.Array variable with Loop command.