Mod 3
Mod 3
1. Sequences
2. Flowcharts
3. User Events
4. State Machines
1. Sequences
2. Flowcharts
3. User Events
4. State Machines
A Flowchart provides multiple branching logical operators to make decisions. A Flowchart is able to run
in reverse. Also, it can be used inside Sequences. A Flowchart facilitates reusability for distinct projects.
Once we create it to use in a project, it can be used for a different but similar project.
A Flowchart's branches are set to true/false by default. However, its names can be manually changed
from the Properties panel. For example, enter two numbers and check whether their sum is less than
20.
1. First, add a Flowchart from the Activities panel into the Designer panel.
2. Add a Sequence activity within the Flowchart.
3. Take two Input dialog activities (for entering the numbers to be added) inside the Sequence
activity.
4. Create the variables x and y to save the values.
5. Next, add a Message box activity to perform a mathematical operation. In our case, the sum of
the two numbers is less than 20:
x + y < 20
Example
To better understand how the Delay activity works, let us see an example of an automation that
writes two messages to the Output panel with a delay of 50 seconds.
Example
In this example, we will use the Break activity to execute only one iteration.
Example
In the following example, we will see how an integer variable will increase from 5 to 50 in
increments of 5.
Example
Let us take an example to understand how the Do while activity works in automation.
Take an integer variable. Starting with this variable, we shall generate all multiples of 2,
less than 20.
Example
In the following example, we shall use the For each activity to go through a collection of even
numbers and display each element one at a time.
Perform the following steps:
7. Now, run the program. You will see that each number of the array is displayed one by one
because of the use of the For each activity:
7. The If activity
The If activity consists of a statement with two conditions: true or false. If the statement is true, then
the first condition is executed; if not, the second condition is executed. This is useful when we have to
take decisions on the basis of statements.
To better understand how the If activity works, let us see an example that checks whether the sum of
any two numbers is less than 6.
By default, the Switch activity takes an integer argument. If we want to take a desired argument,
then we can change it from the Properties panel, from the TypeArgument list. The Switch
activity is very useful in the categorization of data according to one's own choice.
Example
Let's see an example where we have to check whether a given number is odd or even.
We know that all odd numbers, when divided by 2, leave a remainder of 1. On the other hand,
even numbers, on being divided by 2, leave a remainder of 0. Hence, we will have two cases
getting a remainder of 1 or 0.
There may be different Sequences doing their jobs. We can easily put similar Sequences into a workflow;
each workflow represents a task. It is very easy to test a separate workflow alone. Let us try to
understand them better with an example.
1. Drag and drop a Flowchart onto the Designer panel. Drag and drop a Sequence activity. Connect
the Sequence activity with the Start node.
2. Double click on the Sequence activity. Drag and drop an Input dialog activity and a Message box
activity. Specify a message in the label property of the Input dialog activity.
3. Create a variable of type String. Give it a name. Also, specify this newly created variable's name
in the content property of the Message box activity:
We are not going to implement the actual code for sending the email. It will be covered later in detail.
The aim of this session is to clearly understand where and how we use workflows and Sequences.
1. Drag and drop two Flowchart activities on the main Flowchart. Rename them as Send
Mail and Message.
We have two different workflows. The Send Mail workflow will send the mail to an email
address. The Message workflow has the message body of that email and will ask the user for a
name, message, sender, and receiver.
For that, we are using a Sequence inside the Flowchart. Double click on the Flowchart. Drag and
drop a Sequence activity inside both Flowcharts. Connect the Sequence to the Start node by
right-clicking on the Sequence and selecting the Set as Start node option.
3. Double click on the Sequence in the Message Flowchart. Drag and drop four Input
dialog activities for the name, message, sender, and receiver (in this Sequence, we are not
going to set any property of the Message box since the purpose of this lesson is to clearly
understand where and how we use workflows and Sequences):
4. Double click on the Send Mail Flowchart. Double click on the Sequence. You can drag
and drop the email activities here. (We are not going to drag any mail activity although
you are free to do so. There is another chapter for that).
5. That's it. Now, go to the main Flowchart. Connect the Message Flowchart to
the Start node. Also, connect the Send Mail activity to the Message Flowchart:
Consider an array of names. Say we have to find out how many of them start with the letter a.
We will then create an automation where the number of names starting with a is counted and the
result is displayed.
Also, initialize the array in the Default section of the variable by giving it a default values. For
example, {"John", "Sam", "Andrew", "Anita"}.
4. Create a variable of type integer Count for storing the result. Set the variable type to Int32:
5. Drag and drop a For each activity inside the Sequence. Also, specify the array name in the
expression box of the For each activity. The For each activity is used to iterate over the array. It
will pick up one name from the array each time until it reaches the end:
6. Drag and drop the If activity from the Activities panel and place it inside the For
each activity at the location where Drop activity here is mentioned. Specify the condition
in the expression box of the If activity. The If activity is used to check for a particular
condition/expression. If that expression is satisfied, the Then block will be executed.
Otherwise, the Else block will be executed.
7. Now, we are going to use the Count variable and increment it each time a name from an array
starts with the letter a. For this, we have to use the A+B Assign activity. Drag and drop the A+B
Assign activity inside the If activity. Set the To property to Count (variable name) and
the Value property to Count+1 (to increment its value) of the A+B Assign activity:
8. Just drag and drop a Message box activity inside the Sequence activity. Specify the count
variable in the expression box of the Message box activity. But remember, the variable
that we have created is of type Int32, so, it cannot be used with the Message box activity
without converting it to a string. To convert it to a string, we have
the '.toString' method available in UiPath Studio. Just apply it to the variable and
select '.toString':
Hit the Run button or press F5 and see the result.
6. What is a Variable?
Example:
Type Content
Example:
Scope of Variables
Avoid setting the scope to the entire workflow unless absolutely necessary.
Steps:
1. Declare a Variable:
o Name: greetingMessage
o Type: String
o Default Value: "Hello, World!"
7. Collections in UiPath
Collections allow you to store multiple data points of the same or different types, depending on
the collection type. They are essential for handling and managing multiple pieces of data
efficiently.
Types of Collections
1. Scalar Variables: Store a single data point (e.g., Integer, Double, String).
2. Collections: Store multiple data points of the same or compatible types (e.g., Array, List,
Dictionary).
3. Tables: Represent data in a structured, tabular format (e.g., DataTable).
Understanding Collections
Array: A fixed-size collection that holds multiple elements of the same data type.
List: A dynamic collection that can grow or shrink as needed.
Dictionary: A key-value pair collection for fast lookups.
Objective: Initialize an array of integers, iterate through its elements, and display them using a
Message Box.
Steps:
1. Create a Flowchart:
o Drag and drop a Flowchart activity into the main Designer panel.
2. Add a Sequence:
o Drag and drop a Sequence activity inside the Flowchart.
o Set the Sequence as the Start Node.
Key Points:
For Each Activity: Automatically generates an item variable representing the current element in
the loop.
ToString Method: Converts non-string types to a string, required for Message Box input.
Output
1. Each number in the array (1, 2, 3, 4, 5) is displayed sequentially in separate Message Boxes.
Advantage of Collections
1. Efficient Data Management: Handle multiple values without creating multiple variables.
2. Iterative Operations: Easily perform actions on each item in a collection.
3. Dynamic Behavior: Lists and dictionaries adapt to changing data sizes and relationships
8. Arguments in UiPath
Arguments in UiPath are used to pass data between workflows, enabling interaction and data
exchange in modular automation projects. Unlike variables, which are limited to a specific scope,
arguments have a broader role, as they facilitate communication across workflows.
Purpose of Arguments
1. Workflow Modularity: Break down large projects into smaller, manageable workflows.
2. Data Exchange: Transfer data between workflows efficiently.
3. Improved Testing: Test individual workflows in isolation with defined inputs and outputs.
4. Reusability: Reuse workflows across different projects by defining flexible arguments.
In Receive data from the caller workflow. Pass input values into a workflow.
Out Send data to the caller workflow. Pass output values from a workflow.
Scenario:
Workflow A:
Workflow B:
Execution Flow:
A Data Table in UiPath is a tabular data structure used for storing and manipulating data in rows
and columns, similar to how data is organized in a spreadsheet or database. It is extensively used
in automation workflows for building, manipulating, and processing data dynamically.
2. Set Up Activities:
o Drag a Flowchart activity onto the Designer Panel.
o Inside the Flowchart, place a Sequence activity and set it as the start node.
yaml
CopyEdit
Name: Andrew Jose, Roll_No: 1, Class: 3
Name: Jorge Martinez, Roll_No: 2, Class: 3
Name: Stephen Cripps, Roll_No: 3, Class: 2
plaintext
CopyEdit
row("Name").ToString + "-" + row("Roll_No").ToString + "-" +
row("Class").ToString
Clipboard management involves managing the clipboard's activities, such as copying text to the
clipboard, retrieving text from it, and using it in automation workflows. UiPath provides
activities like Get From Clipboard and Copy Selected Text to simplify clipboard interactions.
Open UiPath Studio and drag the Flowchart activity to the Designer panel.
Click on the Recording button in the toolbar and select Desktop Recording from the dropdown
menu.
Open Notepad:
o Start recording and click on Notepad to open it.
Type Data:
o Click on the Notepad text area.
o Use the Type Into activity to enter text (e.g., "Hello, UiPath!").
o Check the Empty Field checkbox to clear any existing text in Notepad.
Select All:
o Click on the Edit menu.
o Choose the Select All option to highlight the text in Notepad.
Copy Text:
o Again, click on the Edit menu.
o Select the Copy option to copy the highlighted text to the clipboard.
1. Read cell
2. Write cell
3. Read range
4. Write range
5. Append range
The Read Cell activity in UiPath allows you to extract the value of a specific cell from an Excel
file. Below is a step-by-step guide to demonstrate how to use the Read Cell activity.
css
CopyEdit
| A | B | C |
|-------|-------|-------|
| Name | Age | City |
| John | 25 | NY |
| Alice | 30 | LA |
Flowchart:
o Drag and drop a Flowchart activity into the Designer panel.
Excel Application Scope:
o Drag and drop the Excel Application Scope activity inside the Flowchart.
o Connect it to the Start node.
Drag and drop the Read Cell activity inside the Excel Application Scope activity.
Configure the following:
o Range: Specify the cell to read (e.g., B3).
o Output: Create a variable of type String (e.g., Result) to store the value of the cell.
o Assign this variable to the Output property.
Drag and drop the Message Box activity inside the Excel Application Scope.
Configure the Text property to display the value stored in the variable (e.g., Result).
The Write Cell activity in UiPath allows you to write a specific value into a cell of an Excel file.
Here's a step-by-step guide to using this activity.
Steps to Write a Cell Value
Create or have an Excel file ready with existing or blank data. For example:
css
CopyEdit
| A | B | C |
|-------|-------|-------|
| Name | Age | City |
| John | 25 | NY |
| Alice | 30 | LA |
Flowchart:
o Drag and drop a Flowchart activity into the Designer panel.
Excel Application Scope:
o Drag and drop an Excel Application Scope activity into the Flowchart.
o Connect it to the Start node.
o Specify the file path of the Excel file in the WorkbookPath property.
Drag and drop the Write Cell activity inside the Excel Application Scope.
Configure the following:
o Range: Specify the cell where you want to write (e.g., C3).
o Value: Enter the value to write in the cell (e.g., "Seattle").
The Read Range activity in UiPath is used to read a specified range of data from an Excel file
into a DataTable. If no range is specified, the entire worksheet is read.
Example:
css
CopyEdit
| A | B | C |
|-------|-------|-------|
| Name | Age | City |
| John | 25 | NY |
| Alice | 30 | LA |
| Mark | 28 | SF |
1. Flowchart:
o Drag and drop a Flowchart activity into the Designer panel.
3. Read Range:
o Drag and drop the Read Range activity inside the Excel Application Scope.
o Specify the range you want to read:
Leave Range blank to read the entire sheet.
Specify a range (e.g., "A1:C3") to read specific cells.
o Create a variable of type DataTable to store the output (e.g., MyDataTable).
o Assign this variable in the Output property.
5. Message Box:
o Drag and drop a Message Box activity.
o Set the Text property to the variable containing the string (e.g., Result).
Execution
1. Press F5 or click the Run button.
2. The workflow will:
o Open the Excel file.
o Read the specified range into a DataTable.
o Convert the DataTable into a string format.
o Display the data in a pop-up window.
The Write Range activity is used to write data into an Excel worksheet from a DataTable. It
outputs the data in a structured format, starting from the specified range.
2. Configure Columns:
o Delete default columns by clicking the trash icon.
o Add new columns:
Click the + icon.
Specify the column name (e.g., Name, Roll).
Choose a Data Type (e.g., String, Int32).
o Repeat for each column.
3. Initialize Rows:
o Add rows directly by filling in values for each column in the table preview.
4. Create a Variable:
o Create a DataTable variable (e.g., MyDataTable).
o Assign this variable to the Output property of the Build Data Table activity.
Execution
The Append Range activity allows you to add new data to an existing Excel file. The data is
appended to the end of the existing data in the worksheet, making it a useful activity when you
need to update an Excel file without overwriting its existing content.
Execution
This section explains how to work with data in Excel files and convert them into DataTable
objects, and also how to write a DataTable into an Excel file. Below are the step-by-step
procedures for each operation:
In this example, we'll read data from an Excel file and store it in a DataTable.
Steps:
Steps:
1. Build a DataTable:
o Drag and drop the Build Data Table activity from the Activities panel.
o Click on the DataTable property to configure the DataTable structure.
o In the Build Data Table configuration window, delete the two default columns and add
your own columns (e.g., "Name" and "Roll").
o Set the Data Type of the columns (e.g., String for "Name" and Int32 for "Roll").
Example
Alice 101
Bob 102
Excel File After Writing Data (Generated by the Build Data Table Activity)
Name Roll
John 103
Charlie 104