0% found this document useful (0 votes)
3 views18 pages

UiPath Variables and Best Practices

Uploaded by

siddhantchatgpt
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views18 pages

UiPath Variables and Best Practices

Uploaded by

siddhantchatgpt
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….

Name of Faculty: Dr. U. Vinay Name of Course: Code:


Kumar
1. What are Variables in UiPath?
• Definition: A variable is a named memory location used to store data during automation.
• Variables make automation dynamic by allowing data to be reused, updated, or passed
between activities.
• Without variables, automation would be static (hard-coded values).
2. Types of Variables
UiPath supports multiple data types depending on the kind of information to be stored:
Common Variable Types
1. String
o Stores textual data.
o Example: "Hello, UiPath!"
2. Int32
o Stores integer numbers (whole numbers).
o Example: count = 25
3. Boolean
o Stores True/False values.
o Example: isLoggedIn = True
4. Double
o Stores decimal numbers.
o Example: price = 1250.75
5. DateTime
o Stores date and time values.
o Example: invoiceDate = 12-Sep-2025 10:30 AM
6. Array / List
o Stores a collection of items.
o Example: string[] emails = {“a@[Link]”, “b@[Link]”}
7. DataTable
o Stores structured, tabular data.
o Example: Excel data imported into automation.
8. Dictionary<TKey, TValue>
o Stores key-value pairs.
o Example: {“EmpID: 101”, “Name: Ravi”}
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar
Variable Naming Conventions and Data Types
Naming Conventions
• Meaningful Names: Always give descriptive names.
o Bad: var1, temp
o Good: customerName, invoiceAmount
• CamelCase / PascalCase:
o Example: userEmail, TotalAmount.

Choosing Data Types


• Always use specific data types over GenericValue when possible.
• This improves:
o Performance (faster execution).
o Readability (developers understand variable type easily).
o Debugging (type errors caught earlier).
4. Variable Scope: Sequence, Flowchart, Global
• Scope defines where a variable can be accessed in a workflow.

Types of Scope in UiPath


1. Sequence-Level Scope
o Variable available only inside that sequence.
o Example: rowCounter used only in “[Link]”.
2. Flowchart-Level Scope
o Variable accessible across all branches inside a flowchart.
o Example: orderStatus accessible in different decision nodes.
3. Global Scope
o Variables defined at [Link] (highest level).
o Accessible across the entire project.
o For cross-workflow data transfer, prefer Arguments instead of too many global
variables.
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

Using Variables Efficiently Across Workflows


Best Practices
1. Use Arguments for Workflow Communication
o Instead of relying on global variables, pass data via In, Out, In/Out arguments.
o Example: Pass invoiceID from [Link] → [Link].
2. Limit Scope
o Keep variables scoped to where they are needed.
o Avoid “project-wide” variables unless absolutely necessary.
3. Initialize Properly
o Always set default values where possible to avoid runtime errors.
o Example: intCounter = 0, strMessage = "".
4. Avoid Overusing GenericValue
o Generic is flexible but can cause errors in type conversion.
o Example: "123" (string) vs 123 (integer).
5. Naming for Clarity
o Use consistent prefixes (str, int, dt, dict) for easier collaboration.
6. Reuse Variables
o Don’t create new variables unnecessarily.
o Example: If you already have dtInvoices, reuse it for filtering rather than creating
dtInvoicesFiltered unless required.

Summary
• Variables are essential for dynamic automation.
• UiPath supports multiple data types like String, Int32, Boolean, DataTable, etc.
• Use clear naming conventions and the right data type for reliability.
• Control scope (sequence, flowchart, global) to avoid errors.
• Use arguments for passing data across workflows, and avoid overusing GenericValue.
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

What are Arguments?


• Definition: Arguments are data carriers that allow you to pass information between
workflows in UiPath.
• While variables store data within a workflow, arguments enable data transfer in and out
of workflows.
• Useful for creating modular, reusable workflows.
Types of Arguments (Direction)
1. In
o Passes data into a workflow.
o The workflow can read but not modify the original value.
o Example: Passing invoiceID into [Link].
2. Out
o Passes data out of a workflow.
o Example: Extracted totalAmount is sent back to the calling workflow.
3. In/Out
o Allows both reading and writing.
o Example: statusFlag is passed into a workflow, updated inside, and returned back.

2. Reusability of Workflows with Arguments


• Arguments make workflows modular and reusable.
• Instead of writing the same steps in multiple places, you can:
1. Create a workflow (e.g., [Link]).
2. Add arguments (username, password).
3. Reuse it across different automations by just passing different values.
Example:
• [Link] with arguments: In: recipientEmail, In: subject, In: body.
• Can be reused in HR, Finance, and Support processes with different values.
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

Collection Types: Arrays, Lists, Dictionaries


Collections store multiple values and are widely used in automation.
Array
• Fixed-size collection of items of the same data type.
• Example: string[] emails = {“a@[Link]”, “b@[Link]”}.
• Good for static data where the number of items is known.
List<T>
• Dynamic collection (can grow or shrink).
• Example: List of Int32 {10, 20, 30}.
• More flexible than Arrays.
• Common in loops and filtering operations.
Dictionary<TKey, TValue>
• Stores key-value pairs.
• Example: Dictionary (Int32, String) = {101 → "Ravi", 102 → "Meena"}.
• Useful for lookup tables (like EmployeeID → EmployeeName).

For Each with Collections – Practical Use Cases


The For Each activity is used to iterate over collections.
Examples
1. For Each (Array of Emails)
o Send an email to each address.
2. For Each (List of File Paths)
o Read and process each file.
3. For Each (Dictionary of Employees)
o Key = EmployeeID, Value = Name → Display or process payroll data.
4. For Each Row in DataTable
o Process structured data from Excel (invoices, student marks, orders).
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

Clipboard Activities: Get From Clipboard, Set To Clipboard


• Definition: Clipboard activities in UiPath allow automation to interact with the system
clipboard (copy–paste memory).
• Activities:
o Get From Clipboard: Retrieves the current text stored in the clipboard.
▪ Example: Copy text from a web form or Excel cell and use it inside
automation.
o Set To Clipboard: Places a given text into the clipboard.
▪ Example: Copy invoice number to clipboard for pasting into ERP systems.
• Usage Scenarios:
o Automating copy-paste operations between apps.
o Extracting values from one application and pasting into another.
o Quick text transfers without saving files.
File Operations: Read Text File, Write Text File, Append Line
• Read Text File:
o Reads the content of a .txt file into a string variable.
o Example: Load configuration details or template emails.
• Write Text File:
o Writes text into a new or existing file (overwrites existing content).
o Example: Save scraped data or generated reports.
• Append Line:
o Adds text to the end of an existing file without overwriting.
o Example: Keep logs of transactions or store multiple entries in one file.

Moving, Copying, and Deleting Files in Workflows


• Move File: Moves a file from one location to another.
o Example: Move processed invoices from “Input” folder to “Archive.”
• Copy File: Creates a duplicate of a file at a new location.
o Example: Backup reports before processing.
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

Real-World Use: File-Process Automation (Logs, Reports)


• Scenario 1 – Log Automation:
o Use Append Line to record every step of automation (success, errors, timestamps).
o Helps in debugging and audit trails.
• Scenario 2 – Report Generation:
o Read data from Excel or database.
o Write or append results into .txt or .csv report files.
o Move reports into shared folder or email attachment.
• Scenario 3 – File Management:
o Automatically clean up old log files after a week.
o Copy daily processed files to a backup drive.
o Move successfully processed documents into “Archive” for compliance.

Summary for Lecture Use


• Clipboard activities → enable copy–paste automation.
• File operations → enable read/write/append of text files.
• File handling → move, copy, delete files systematically.
• Real-world → widely used for logs, reporting, invoice/document automation.
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

Reading from and Writing to Excel/CSV


• Excel Activities:
o Read Range: Reads data from an Excel sheet into a DataTable.
o Write Range: Writes a DataTable into Excel.
o Read Cell / Write Cell: Reads or writes a single cell.
• CSV Activities:
o Read CSV: Reads a .csv file into a DataTable.
o Write CSV: Exports a DataTable into .csv format.
• Best Practices:
o For Excel, use Excel Application Scope when automation depends on Excel-
specific features (e.g., macros).
o For CSV, ensure proper delimiters (, or ;) are used.

Converting Excel/CSV to DataTable and Vice Versa


• To DataTable:
o Read Range / Read CSV → directly outputs a DataTable.
o Useful for bulk processing (filter, sort, loop).
• From DataTable:
o Write Range / Write CSV → converts DataTable back to a file.
o Example: Process 10,000 rows, filter, and export only needed records.

DataTable Filtering, Sorting, and Looping


• Filtering:
o Use Filter DataTable activity to keep/remove rows/columns.
o Example: Keep only rows where Status = "Approved".
• Sorting:
o Use Sort DataTable activity.
o Example: Sort employees by Salary (ascending/descending).
• Looping:
o Use For Each Row in DataTable.
o Access each row → row("ColumnName").ToString.
o Example: Loop through all student records and print marks.s
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

Using Break, Continue (Pass), and Else in Control Structures


• Break: Immediately exits a loop.
o Example: Stop searching once first match is found.
• Continue (Pass in UiPath): Skips the current iteration and moves to the next.
o Example: Skip rows where data is missing.
• Else: Defines the alternate path in decision-making (If activity).
o Example: If InvoiceAmount > 5000 → Approve; Else → Reject.

Hands-On Example: Read Excel → Filter Data → Write to CSV


Scenario: Process an employee salary Excel file and export only high-salary employees to CSV.
Steps:
1. Read Range (Excel Application Scope) → store data in dtEmployees.
2. Filter DataTable:
o Condition: Salary > 50000.
o Output → dtHighSalary.
3. Write CSV → Export dtHighSalary into [Link].
Result:
• Input: [Link] with 500 rows.
• Output: CSV file containing only employees with salary > 50,000.

Summary for Lecture


• Excel/CSV ↔ DataTable is the backbone of RPA data automation.
• Filtering, sorting, and looping help in processing large datasets.
• Break/Continue/Else make workflows flexible and efficient.
• Real-world → payroll, invoices, reports, and compliance data automation.
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

Summary of Sequence, Flowchart, and Control Flow Structures

1. Sequence, Flowchart, and Control Flow


• Sequence → Linear, step-by-step tasks (best for simple processes).
• Flowchart → Visual, non-linear (best for decision-based workflows).
• Control Flow → If, Switch, Loops (While, For Each), Parallel (for decisions & repetition).

2. Variables/Arguments & Data Handling


• Variables → Store data (String, Int32, Boolean, Generic).
• Scope → Sequence, Flowchart, or Global.
• Arguments → Pass data between workflows (In, Out, In/Out).
• Data Handling → DataTables, Arrays, Lists, Dictionaries for structured & dynamic data.

3. Importance of File/Data Operations


• Most RPA automations work with files & data.
• Operations: read/write files, filter/sort data, move/copy/archive files.
• Real-world use: invoices, payroll, reports, logs.

4. Suggested Practice
• Sequence → Read a text file & append date.
• Flowchart → Student grading system (Pass/Fail).
• Control Flow → Loop through Excel & filter salary > 40k.
• File Handling → Move files from Downloads to Archive with timestamp.
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

1. Overview of Unit Learning Objectives


• Understand workflow structuring in RPA.
• Learn control flow activities (If, Switch, Loops, Flowcharts, State Machines).
• Apply data handling (variables, arguments, data tables, collections).
• Use sequences and data operations to build efficient automation workflows.
2. Importance of Workflow Structuring in RPA
• Ensures clarity and readability of automation.
• Improves reusability of components across projects.
• Makes workflows easier to maintain and debug.
• Supports error handling and smoother exception management.
• Enables scalability for large enterprise-level processes.
3. Introduction to Control Flow and Data Handling in UiPath
• Control Flow:
o If/Else → Conditional branching.
o Switch → Multiple decision paths.
o Loops (While, Do While, For Each) → Repeated execution.
o Flowcharts & State Machines → Complex process navigation.
• Data Handling:
o Variables → Store single values.
o Arguments → Pass data between workflows.
o DataTables → Handle structured data (like Excel).
o Collections (Lists, Dictionaries) → Manage dynamic datasets.
4. Relevance of Sequences and Data Operations in Automation Tasks
• Sequences:
o Linear workflows (step-by-step execution).
o Suitable for simple, straightforward tasks.
o Often used as building blocks inside larger workflows.
• Data Operations:
o Enable real-world business automation.
o Examples: filter, sort, merge, transform, and export data.
o Essential for tasks like invoice processing, report generation, and email automation.
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

1. What is a Sequence? When to use it?


Definition
• A Sequence in UiPath is the simplest type of workflow.
• It executes activities linearly, step-by-step from top to bottom.
• Helps to organize smaller processes into a clear and easy-to-read format.
When to Use Sequences
• When the process has a clear, linear flow without many decision branches.
• For small tasks (e.g., read data → process data → write results).
• As building blocks inside bigger workflows (Flowcharts or State Machines).
• Example use-cases:
o Logging into an application.
o Reading and writing data in Excel.
o Sending an email notification.

2. What is a Flowchart? Best Use-Cases


Definition
• A Flowchart is a workflow type that allows non-linear process design.
• Uses nodes and connectors to define different paths of execution.
• Suitable for complex processes with multiple decision points.
Best Use-Cases
• Processes with multiple branches or outcomes.
• When decisions depend on conditions or user inputs.
• For transactional workflows that require multiple checks.
• Example use-cases:
o Customer support ticket resolution (route based on issue type).
o Order processing (different flows for “New Order”, “Return”, “Cancel”).
o Approval workflows (Manager approval vs Auto-approval).
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

Key Differences: Sequence vs. Flowchart vs. State Machine


Feature Sequence Flowchart State Machine
Graphical, branch-
Structure Linear, step-by-step State-driven with transitions
based
Complexity Simple Moderate to High High (best for long-running)
Small tasks, building Complex decision-
Best For Large, rule-based workflows
blocks making
Easy to visualize
Readability Very easy Good for event/state handling
branching
Login to app, Order processing, Order lifecycle, Robotic process
Examples
Read/Write file Routing tasks with multiple states
Execution Multiple paths,
One path only Moves between defined states
Flow flexible

Simple Workflow Design Using Sequences and Flowcharts


Example A: Sequence-Based Workflow
Task: Read invoice data from Excel and send an email.
• Steps in a Sequence:
1. Read Excel file → DataTable.
2. Process each row (invoice).
3. Generate message string.
4. Send email.
• Flow: Linear (no branching).
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

Example B: Flowchart-Based Workflow


Task: Customer order processing.
• Steps in a Flowchart:
1. Input: Order request.
2. Decision Node: Check order type.
▪ If New Order → Process payment → Ship product.
▪ If Return → Validate → Refund process.
▪ If Cancel → Stop shipment → Refund if paid.
• Flow: Branching and conditional paths.

Summary
• Sequences → Linear, simple workflows.
• Flowcharts → Branching, decision-heavy workflows.
• State Machines → Large, rule-based, long-running processes.
• Together, they form the core building blocks of UiPath workflow design.
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

1. Introduction to Control Flow Concepts


• Definition: Control flow defines the order in which activities are executed in a workflow.
• In UiPath, control flow allows bots to:
o Decide what path to take (conditions).
o Repeat activities (loops).
o Branch into multiple directions (Switch, Flowchart).
o Execute tasks in parallel where possible.
• Without control flow, workflows would only execute activities linearly without
intelligence.
Conditional Branching
UiPath provides multiple control flow activities:
If Activity
• Executes one set of activities if the condition is true, another if false.
• Syntax: If (Condition) → Then / Else.
If (invoiceAmount > 10000)
→ Send to Manager Approval
Else
→ Auto Approve

Switch Activity
• Used when there are multiple possible outcomes.
• Cleaner than multiple nested Ifs.
• Example:
o Switch (DocumentType):
▪ Case "Invoice" → Process Invoice
▪ Case "Receipt" → Process Receipt
▪ Case "PO" → Process Purchase Order
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

While Activity
• Repeats a block of activities as long as the condition is true.
• Condition checked before execution.
• Example:
o While (counter < 5) → Perform Data Entry.

Do While Activity
• Similar to While, but condition is checked after execution.
• Ensures block runs at least once.
• Example:
o Do → Try Login → While (LoginSuccess = False).

For Each Activity


• Iterates over collections (List, Array, DataTable).
• Example:
o For Each email in emailList → Send Email.

Parallel Activity
• Executes multiple activities simultaneously.
• Best for independent tasks.
• Example:
o Parallel branches:
▪ Download Report
▪ Send Reminder Email
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

Looping Structures and Their Practical Use


Loop
When to Use Example Use-Case
Type
Repeat until condition fails (pre-
While Retry login attempts until success
check)
Ensure at least one execution (post- Always click “Refresh” once, then continue
Do While
check) checking data
Loop through all rows in Excel or all emails in
For Each Iterate over a collection
Inbox
Parallel Run independent tasks together Extract data from 2 apps simultaneously

Decision Making with Real-World Automation Examples


Invoice Processing
• If invoice > ₹10,000 → Manager approval, else auto-approve.
Email Classification
• Switch (EmailSubject):
o Case “Payment” → Finance folder.
o Case “Job Application” → HR folder.
Data Scraping
• While → keep scraping until “Next Page” button is disabled.
System Login
• Do While → attempt login until LoginSuccess = True.
Bulk Notifications
• For Each email → send personalized notification.
Faculty of: FCE Program: B. Tech Class/Section: IIIrd AIDS (C, D, E) Date: ……………………….
Name of Faculty: Dr. U. Vinay Name of Course: Code:
Kumar

Step-by-Step Examples Combining Sequence + Control Flow

Example A: Processing Student Results


• Sequence + If + For Each
1. Read Excel file (students + marks).
2. For Each student row →
o If (Marks ≥ 40) → Assign “Pass” else “Fail”.
3. Write results back to Excel.

Example B: Web Data Extraction


• Sequence + While
1. Open website.
2. While (NextPage button exists):
o Extract table data.
o Click Next Page.
3. Merge all results into DataTable.

Example C: Order Handling


• Sequence + Switch
1. Get order type.
2. Switch (OrderType):
o Case “New” → Create order.
o Case “Cancel” → Stop shipment.
o Case “Return” → Start refund.
Summary
• Control flow adds intelligence to automation.
• If & Switch → Decision making.
• While, Do While, For Each → Looping.
• Parallel → Simultaneous execution.
• Real-world automations always combine Sequences + Control Flow for flexibility and
efficiency.

You might also like