Reading variable values from an external file

If you do not want to specify a value to a variable when you are creating a variable, you can set a value to the variable by using an external file, such as a text, CSV, Excel, or database file.

Reading from a text file

To read variable values from a text file, perform the following steps:

  1. In the Variable Manager, click the Add button at bottom or right-click on an existing variable and select the Add to invoke the Add Variable check box.

    In the Add Variable window, the Create New Variable option is enabled, by default.

  2. Select the desired variable type, enter a name, and select Read from Text File from the drop-down menu.

  3. To ensure that Automation Anywhere validates the text files correctly when assigning values for the variables, follow these guidelines:
    • One text file can have multiple <variable> = <value>pairs on separate lines (line returns using the Enter key).
    • For value type variables, only one value should be assigned.
    • Example: myvar=value1 where myvar is the name of the variable.
    • Example: my-list-var=value1,value2,value3
    • Ensure that your text file is specified in the Variable Manager before the task runs.
    • For List-type variables, you can define the comma-separated values for the variable.
    • Variable names are not case-sensitive.
    For example, here is a text file with different <variable>=<value> pairs:
    Age=12,13,16,21
    Games=Football,Soccer,Rugby
    username=my-username
    Removed the password field.
Note: When you use the read from file feature to retrieve values from a text file, the associated bot runs successfully even if it is a different user or the filepath is invalid, as long as that text file is available in the following folder:

Automation Anywhere Files\Automation Anywhere\My Docs

Consider a scenario where user1 is currently logged in and has saved the variable.txt text file in the following location:

C:\Users\user1\Documents\Automation Anywhere Files\Automation Anywhere\My Docs\VarFile\variable.txt

Subsequently, user2 can log in and run a bot to successfully retrieve the values from variable.txt even if the following filepath, specific to user 2, does not exist:

C:\Users\user2\Documents\Automation Anywhere Files\Automation Anywhere\My Docs\VarFile\variable.txt

Automation Anywhere Enterprise is designed to create an access path to the text file as long as it is available in Automation Anywhere Files\Automation Anywhere\My Docs.

Reading from an Excel file

When you create an array-type variable and specify that values should be read from an Excel file, data can be read for the following:

  • For an entire row
  • For an entire column
  • For a range of cells that you specify using the From and To fields

Reading from a database

To read values from a database file, you must specify a connection string and a SELECT query.

Note: Reading variable from database is applicable only for array-type variables.