Example of using a file variable

Learn to use file variables in bots. There can be instances where a bot needs to access a file multiple times based on the task it performs. You can store file references in file variables and use the file variables in bots instead of adding direct file paths.

In this example, the sample bot does the following:
  • Uses a file variable to access a CSV file.
  • Opens and reads data from the file using the file variable.
  • Retrieves and displays the address of an employee as a message.
If you do not already have a sample CSV file with addresses, you can copy the following data to a text file and save it as a CSV file on your computer:
Roy, Doe, 120 Jefferson St., Riverside, IT_PROG
Shaun, McGinnis, 220 Hobo Av., Rocky Point, FI_ACCOUNT
John, Mark, 124 Jefferson St., Riverside, SA_HEAD
Sophie, Tyler, 7300 Terrace "At the Plaza" Rd., Wells, IT_PROG
Stephen, Mathew, 22 Theressia St., Troy, IT_PROG
Anne, Ross, 9th St., Lexington, IT_PROG

Procedure

  1. Create a bot.
    1. On the left panel, click Automation.
      A list of available bots and forms is displayed.
    2. Click Create New > Task Bot.
    3. Enter Employee Data as the name for the bot.
    4. Click Create and Edit.
  2. Create a variable named varFile.
    1. Click Create variable in the Variables panel.
    2. In Type, select File as the variable type.
    3. In Name, enter varFile.
    4. Select Desktop folder or file.
    5. In Specific path, click Browse and select the sample CSV file you have on your computer.
    6. Click Create.
  3. To open the CSV file using the file variable, find the CSV/TXT package from the Actions panel, and add the Open action to the Bot editor.
    1. In File path, click Variable and enter $varFile$.
    2. Ensure that Comma is selected as delimiter if you are using the sample data provided in the tutorial. If your CSV file uses another delimiter, specify the delimiter.
    3. Click Save.
  4. To read the CSV file, find the CSV/TXT package from the Actions panel, and add the Read action to the Bot editor.
    1. In Assign value to the variable, click (x) to create a variable named TableFromCSV. The values read from the CSV file will be stored in the variable.
    2. Click Save.
  5. To display the address from the fourth row as a message, add the Message Box action to the Bot editor.
    1. In Enter message to display, click (x).
    2. Select the TableFromCSV variable.
    3. To select the fourth row, enter 3 in Table row index.
    4. To select the third column, click Index in Table column, and then enter 2.
      Ensure that the value entered in the Enter message to display text field is $TableFromCSV[3][2]$.
    5. Click Yes, insert.
    6. Click Save.
  6. Run the bot.
    The bot displays the address: 7300 Terrace "At the Plaza" Rd.