RPA Variables and Data Types

A variable is a named container that holds a value while your bot is running. The bot reads from variables, writes to them, passes them between workflow steps, and uses them to make decisions. Without variables, a bot cannot store or reuse any information it reads from a screen or file.

Think of a variable like a labelled sticky note on the bot's desk. The bot writes a value on the note, refers to it later, and erases it when the workflow ends.

Variable Lifecycle

 BOT STARTS
     │
     ▼
 Variable "invoiceAmount" is declared (created, empty)
     │
     ▼
 Bot reads value from PDF: 1,500.00
 → Assigns to variable: invoiceAmount = 1500.00
     │
     ▼
 Bot uses variable in decision:
 → IF invoiceAmount > 5000 THEN send for approval
     │
     ▼
 Bot passes variable to SAP:
 → Types invoiceAmount into Amount field
     │
     ▼
 BOT ENDS → Variable "invoiceAmount" is destroyed

Common Variable Data Types in RPA

String

A String holds text — any combination of letters, numbers, spaces, and symbols. Strings are used for names, addresses, codes, URLs, and email addresses.

 customerName = "John Smith"
 invoiceRef   = "INV-2024-0451"
 emailAddress = "vendor@company.com"

Integer

An Integer holds a whole number (no decimal places). Use integers for counts, loop counters, or quantities.

 rowCount    = 200
 loopIndex   = 1
 retryCount  = 0

Double / Decimal

A Double or Decimal holds numbers with decimal places. Use these for financial amounts, percentages, or any value that needs precision.

 invoiceAmount  = 1500.75
 taxRate        = 0.18
 totalPayable   = 1771.89

Boolean

A Boolean holds only two values: True or False. Use Booleans as flags — to record whether a check passed, whether a vendor was found, or whether an error occurred.

 isVendorApproved  = True
 isLoginSuccessful = False
 hasException      = True

DateTime

A DateTime variable holds a date and time value. Use it to store invoice dates, processing timestamps, or deadlines.

 invoiceDate    = 15/03/2024 00:00:00
 processedAt    = 15/03/2024 09:34:22
 dueDate        = 14/04/2024 00:00:00

DataTable

A DataTable is like a spreadsheet in memory — it has rows and columns. Use it when the bot reads a full Excel sheet or database table and needs to process each row one by one.

 DataTable: invoiceTable
 ┌──────────────┬────────────────┬──────────┬────────┐
 │ Vendor       │ Invoice No.    │ Amount   │ Date   │
 ├──────────────┼────────────────┼──────────┼────────┤
 │ Acme Ltd     │ INV-2024-0451  │ 1500.75  │15/3/24 │
 │ Beta Corp    │ INV-2024-0452  │  780.00  │15/3/24 │
 │ Gamma Inc    │ INV-2024-0453  │ 4200.50  │15/3/24 │
 └──────────────┴────────────────┴──────────┴────────┘

List (Array)

A List holds multiple values of the same type in a sequence. Use it when you need to store a collection of items — such as a list of email addresses, file names, or product codes.

 emailList = ["ap@company.com", "finance@company.com", "cfo@company.com"]
 fileList  = ["invoice1.pdf", "invoice2.pdf", "invoice3.pdf"]

Variable Scope

Scope defines where in the workflow a variable can be used. In UiPath:

  • Local scope: The variable is only available inside the current sequence or flowchart where it was created.
  • Global / Argument: The variable is passed between workflows using Arguments (inputs and outputs), making it accessible across multiple workflow files.

Scope Example

 Main.xaml
 ├── Variable: invoiceData (DataTable) — scope: Main
 │
 ├── Calls ProcessInvoice.xaml
 │       → Passes invoiceData as IN Argument
 │       → Receives sapDocNumber as OUT Argument
 │
 └── Uses sapDocNumber back in Main to log result

Arguments vs Variables

FeatureVariableArgument
ScopeWithin one workflowPassed between workflows
DirectionN/AIn, Out, or In/Out
Created InVariables panelArguments panel
Use CaseTemporary data storageCommunication between workflows

Naming Variables — Best Practices

  • Use camelCase naming: invoiceAmount, customerName, rowCount
  • Use descriptive names: vendorIsApproved (not just flag)
  • Prefix by type if needed: dt_invoiceData for DataTables, str_vendorName for Strings
  • Avoid single letters: x, y, i make code unreadable (except for simple loop counters)
  • Use prefixes for Arguments: in_ for inputs, out_ for outputs, io_ for both

Working with Strings — Common Operations

 Concatenation (joining text):
   fullName = firstName + " " + lastName
   Result: "John Smith"

 Trimming whitespace:
   cleanName = vendorName.Trim()
   "  Acme Ltd  " → "Acme Ltd"

 Converting to uppercase:
   upperCode = invoiceRef.ToUpper()
   "inv-2024" → "INV-2024"

 Checking if a string contains a word:
   IF invoiceSubject.Contains("Invoice") THEN process it

 Replacing text:
   cleanAmount = rawAmount.Replace(",","").Replace("$","")
   "$1,500.75" → "1500.75"

Summary

Variables are named containers that store data while a bot runs. The most common types are String (text), Integer (whole numbers), Double (decimals), Boolean (True/False), DateTime (dates), DataTable (tables), and List (collections). Arguments pass variables between workflow files. Good naming conventions make workflows readable and maintainable. Every bot uses variables — mastering them is essential for building any real automation.

Leave a Comment

Your email address will not be published. Required fields are marked *