0% found this document useful (0 votes)
18 views46 pages

Utilizing External Code

Uploaded by

210701014
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)
18 views46 pages

Utilizing External Code

Uploaded by

210701014
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
You are on page 1/ 46

Advanced RPA

Design & Development


v4.0
Advanced RPA Design and Development v4.0 June 2022

Slide 1

Welcome to ‘Advanced RPA Design and Development Course.’

1|Page
Advanced RPA Design and Development v4.0 June 2022

Slide 2

Lesson 7

Utilizing External Code

The seventh lesson of this course is Utilizing External Code.

2|Page
Advanced RPA Design and Development v4.0 June 2022

Slide 3

Agenda

01 Invoke Method Activity 04 Invoke VBA Activity

02 Invoke Code Activity 05 Python Activities Package

03 Invoke PowerShell Activity 06 Java & Inject JS Script Activity

The agenda of this lesson is:


• Invoke Method Activity
• Invoke Code Activity
• Invoke PowerShell Activity
• Invoke VBA Activity
• Python Activities Package
• Java and Inject JS Script Activity

3|Page
Advanced RPA Design and Development v4.0 June 2022

Slide 4

Learning Objectives

01 Explain Invoke Method Activity

02 Explain Invoke Code Activity

03 Explain Invoke PowerShell Activity

04 Explain Invoke VBA Activity

05 Explain Python Activities Package

By the end of this lesson, you will be able to:


• Explain Invoke Method Activity
• Explain Invoke Code Activity
• Explain Invoke PowerShell Activity
• Explain Invoke VBA Activity
• Explain Python Activities Package

4|Page
Advanced RPA Design and Development v4.0 June 2022

Slide 5

Learning Objectives (Contd.)

06 Explain Java and Inject JS Script Activity

• Explain Java and Inject JS Script Activity

5|Page
Advanced RPA Design and Development v4.0 June 2022

Slide 6

Programming
Languages in Studio
• Introduction to Programming Languages in Studio

This section introduces the Programming Languages used in Studio.

6|Page
Advanced RPA Design and Development v4.0 June 2022

Slide 7

Introduction to Programming
Languages in Studio
Studio can be used with several programming languages such as:

PowerShell C#

VBA VB.NET

Python Java and JavaScript

Studio can be used with several programming languages such as:

• PowerShell: PowerShell is a task automation programming language used to


create batch processes and customized system management tools in Windows
• VBA: Visual Basic for Applications (VBA) is a partially compiled programming
language used for Excel and other Office applications
• VB.NET: It stands for Visual Basic.NET, and it is a computer programming
language developed by Microsoft
• Python: Python is a high-level, general-purpose programming language
• C#: C# is a programming language developed by Microsoft. It runs on the .NET
framework
• Java: Java is a class-based, object-oriented programing language, which is
designed to have minimal dependencies
• JavaScript: JavaScript programming language is commonly used to make
dynamic web pages

External code written in these programming languages can be executed from the
Studio platform. How to specify exactly what code to be executed and what
arguments to be passed to and through which activities are discussed in further
slides.

7|Page
Advanced RPA Design and Development v4.0 June 2022

Slide 8

Invoke Method Activity


• Introduction to Invoke Method Activity
• Properties of Invoke Method Activity
• Types of Methods in Invoke Method Activity
• Example of Static Method in Invoke Method Activity
• Example of Non-Static Method in Invoke Method Activity
• Configure Invoke Method Activity for DLL File

This section introduces the Invoke Method Activity.

8|Page
Advanced RPA Design and Development v4.0 June 2022

Slide 9

Introduction to Invoke Method Activity

Invoke Method activity is used to call a method that is outside the standard built-in activities of Studio,
such as in a DLL file.
Invoke Method Activity

Calls a specific method in a class

Calls a public method of a specified type or object

Acts on either Target Type or Target Object

Invoke Method activity is used to call a method that is outside the standard built-in
activities of Studio, such as in a DLL (Dynamic Link Library) file.
• It is used to call a specific method in a class
• The activity calls a public method of a specified type or an object
• It acts on either Target Type or Target Object

9|Page
Advanced RPA Design and Development v4.0 June 2022

Slide 10

Properties of
Invoke Method Activity
The properties of Invoke Method activity are:

GenericTypeArguments Parameters
Sets the generic type arguments Enters the list of parameters to be
passed to the method

MethodName Result:
Inserts the method name to be Enters a variable to store the
invoked output

Private TargetObject
Specifies whether this activity will Passes the object whose method
be private or public is invoked

RunAsynchronously:
TargetType
Specifies whether this activity will
Specifies the data type of the
execute synchronously or
target
asynchronously

The properties of Invoke Method activity are:

• GenericTypeArguments: Sets the generic type arguments


• MethodName: Inserts the method name to be invoked
• Parameters: Enters the list of parameters to be passed to the method
• Private: Specifies whether this activity will be private or public
• Result: Enters a variable to store the output
• RunAsynchronously: Specifies whether this activity will execute synchronously
or asynchronously
• TargetObject: Passes the object whose method is invoked
• TargetType: Enters the target whose method is invoked

10 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 11

Types of Methods
in Invoke Method Activity
Invoke Method activity can be configured with the following methods:

Static Method Non-Static Method


• Used for a class defined as static • The object (from which the method
• No need to define the object is derived) needs to be defined
• TargetType is used • TargetObject is used

Invoke Method activity can be configured with the following methods:

• Static Method:
• Used for a class defined as stati
• There is no need to define the object. Thus, the Static method can be
called directly. (TargetObject field in the Invoke Method activity is left
empty)
• Target type is used. (Example: System.Console)

• Non-Static (Instance) Method:


• The object (from which the method is derived) needs to be defined
• There is no need to select any other TargetType here, it is left with (null)
option
• Target Object is used. (Example: DataTable)

11 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 12

Example of Static Method


in Invoke Method Activity
An example of Static Method in Invoke Method Activity is shown below:

1 Complete workflow

Parameters of the
Invoke Method activity 2

Output of the workflow


3

An example of Static Method in the Invoke Method activity is shown on the slide in
which local time is converted to a specific time zone using an Invoke Method activity.
Following are the steps to build the workflow:

Step 1: Insert an Assign activity in the Designer panel. In its To field, create a
DateTime variable named in_LocalDateTime. In its Value field, enter Now.
Step 2: Insert a second Assign activity below the previous Assign activity. In its To
field, create a TimeZoneInfo variable (select the Browse for Types option from the
Variable Type dropdown and search for TimeZoneInfo class) named
in_destTimeZone. In its Value field, enter
TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")
Step 3: Insert an Invoke Method activity below the second Assign activity and pass
the values as below:
a. In the TargetType field, select System.TimeZoneInfo
b. In the MethodName field, enter ConvertTime
Step 4: In the Parameters property of the Invoke Method activity, enter
in_LocalDateTime and in_destTimeZone of direction In and type DateTime and
TimeZoneInfo respectively (screenshot 2).
Step 5: Run the workflow to get the Output (screenshot 3).

12 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 13

Example of Non-Static Method


in Invoke Method Activity
An example of Non-Static Method activity in Invoke Method Activity is shown below:
1
Complete workflow
Parameters of the
Invoke Method activity 2

Output of the workflow


3

An example of Non-Static Method in the Invoke Method activity is shown. In this


example, two DataTables are being merged using an Invoke Method activity. Given
below are the steps:

Step 1: Insert a Build Data Table activity in the Designer panel. Build a DataTable
with two columns. First column as the list of places and the second column as the list
of item IDs. In its Output property, press Ctrl + K to create a DataTable variable
named in_dt_cityListOne.
Step 2: Insert a second Build DataTable activity below the previous Build Data
Table activity. Build a DataTable with two columns. First column as the list of places
and second column as the list of item IDs. In its Output property, press Ctrl + K to
create a DataTable variable named in_dt_cityListTwo.
Step 3: Insert an Invoke Method activity below the second Build Data Table activity
and pass the values as below:
a. In the TargetType field, enter Null.
b. In the TargetObject field, enter in_dt_cityListTwo.
c. In the MethodName field, enter Merge.
Step 4: In the Parameters property of the Invoke Method activity, enter
in_dt_cityListOne of direction In and type DataTable (screenshot 2).
Step 5: Insert an Output Data Table activity below the Invoke Method activity. In its
DataTable property, enter in_dt_cityListTwo. In its Text property, press Ctrl + K and
enter Result.
Step 5: Insert a Message Box activity below the Output Data Table activity. In the
Text property, press Ctrl + K to create a new variable named Result.
Step 6: Run the workflow to get the output (screenshot 3).

13 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 14

Configure Invoke Method


Activity for DLL Files
The steps to call a method from a DLL file using Invoke Method Activity are:

Download a NuGet package containing DLL files from Nuget.org


Step 1

Install the NuGet package in Studio


Step 2

Call the specified method using Invoke Method activity


Step 3

The steps to call a method from a DLL file using Invoke Method Activity are:

1. Download a NuGet package containing DLL files from Nuget.org


A NuGet package comes with .nupkg extension, which contains DLL files. A
.nupkg file for a specific functionality can be created manually as well as
downloaded from trusted sources. In Studio, Nuget.org can be used as a
package source in Manage Packages. A user can directly search for a
required package by searching through the NuGet database in the Manage
Packages window. If Nuget.org is not already configured in Manage
Packages, then it can be configured by adding the NuGet source in “User
defined package sources” section found under Settings tab. Package source
link for Nuget.org is: https://api.nuget.org/v3/index.json.

2. Install the NuGet package in Studio


A downloaded NuGet package can be installed in Studio through Manage
Packages window. In the Settings tab, the local folder containing the package
must be added as a package source. After adding the folder as a source, the
folder name will reflect on the left panel. The folder name can be clicked to
view the list of packages within that folder. Here, a package can be clicked to
show its detail on the left panel. To install the package, Install button displayed
in the left panel should be clicked.

3. Call the specified method using the Invoke Method activity


Methods from an installed package can be called in a project by using Invoke
Method activity. A user can search for types by using Browse for Types.

14 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 15

Invoke Code Activity


• Introduction to Invoke Code Activity
• Invoke Code Activity with VB.NET and C#

This section introduces the Invoke Code Activity.

15 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 16

Introduction to
Invoke Code Activity
Invoke Code activity can be used to synchronously invoke VB.NET or CSharp (C#) code and write
custom code for some steps in the process.

It helps the users to: Arguments


• Simplify data manipulation Pass the parameters to the invoked
procedures code
• Reduce the number of
Assign and Invoke Method Code
activities, by replacing Pass the code to be invoked
several with a single
Invoke Code activity Language
Select the programming language
(VB.NET or C#)

Invoke Code activity is used to synchronously invoke VB.NET and CSharp (C#)
code. It helps the user to write custom code as required within steps in a process,
simplify data manipulation procedures, and reduce the number of Assign and
Invoke Method activities, by replacing several activities with a single Invoke Code
activity.

Properties:
• Arguments: The parameters that can be passed to the code to be invoked
• Code: The code that is to be invoked. This field supports only strings
and String variables
• Language: The drop-down menu specifies the language in which the invoked
code is written. The available options are VB.NET and CSharp

To know more, visit: https://docs.uipath.com/activities/docs/invoke-code

16 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 17

Invoke Code
Activity with VB.NET and C#

Invoke Code Activity with VB.NET Invoke Code Activity with C#


• VB.NET code is used inside the • C# code is used inside the Invoke
Invoke Code activity Code activity
• Example: A VB.NET code for adding • Example: A C# code for adding two
numbers is invoked using the activity numbers is invoked using the activity

Invoke Code Activity with VB.NET: VB.NET code is used inside the Invoke Code
activity.
• Example: The Input Dialog activity takes a number from the user as an input. A
VB.NET code for adding the number with three predefined numbers is invoked
using the activity

Invoke Code Activity with C#: C# code is used inside the Invoke Code activity
• Example: A C# code for adding two numbers is invoked using the activity

Invoke Code activity contains the following buttons:


• Edit Code button is used to input VB.NET or C# code to be executed
• Edit Arguments button is used to pass input arguments to the code

Passing Arguments in Invoke Code activity


Arguments in the code can be passed by inserting the specified argument using the
Arguments button on the Invoke Code activity. Alternatively, ellipsis button of the
Arguments property from the Properties panel of the Invoke Code Activity can be
clicked. Clicking on the button will open a popup window, which contains four
columns –
• Name - In the Name column, the name of the argument is entered
• Direction - In the Direction column, the direction of the respective argument is
defined, which can be In, Out, or In/Out
• Type - In the Type column, the Argument type can be defined as String, Int32, or
others
• Value. In the Value column of a respective argument, values can be entered as
required based on the selected Type. The Value column can be left blank as well

To know more, visit: https://docs.uipath.com/activities/docs/invoke-code

17 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 18

Invoke PowerShell Activity


• Introduction to Invoke PowerShell Activity
• Properties of Invoke PowerShell Activity

This section introduces Invoke PowerShell activity and its properties.

18 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 19

Introduction to
Invoke PowerShell Activity
Windows PowerShell is a task automation and configuration management framework by Microsoft.

Invoke PowerShell activity:


• Executes PowerShell
command with specified
input parameters
• Runs one-liner command
from within the activity or
multiple lines of commands
using a script file

Generate a list of current system


services and display the output

Windows PowerShell is a task automation and configuration management framework


by Microsoft. PowerShell consists of a command-line shell and scripting language. It
can be used to control and configure almost every aspect of Windows. Invoke
PowerShell activity is used to execute PowerShell commands. It can be used to run
one-liner PowerShell commands or multiple lines of commands using a script file.

The screenshot shows the Invoke PowerShell activity within a workflow. The
workflow displays a list of current system processes in the output panel upon
execution.

To know more, visit: https://docs.uipath.com/activities/docs/invoke-power-shell

19 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 20

Properties of
Invoke PowerShell Activity
The properties of Invoke PowerShell activity are:

CommandText Parameters
Passes the PowerShell commands Enters a dictionary of PowerShell
to be executed command parameters

Input Type Argument


Passes the collection of Sets the type of the output
PSObjects to the command variable

PowerShellVariables Output
Passes variables to be used in the Stores the TypeArgument object
current session of the command returned after command execution

The properties of Invoke PowerShell activity are:

• CommandText: Passes the PowerShell commands to be executed


• Input: Passes the collection of PSObjects to the command
• Parameters: Enters a dictionary of PowerShell command parameters,
Dictionary<String, InArgument>
• PowerShellVariables: Passes the variables to be used in the current session of
the command
• Type Argument: Sets the type of the output variable
• Output: Stores the TypeArgument object returned after command execution

To know more, visit: https://docs.uipath.com/activities/docs/invoke-power-shell

20 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 21

Practice Exercise

Build a workflow using Invoke PowerShell activity that


creates two text files in the project folder and moves
both the files to a new folder. The workflow should:

• Create two text files in the project folder


• Open both the files to show their contents and close the files
• Inform the user that a folder will be created to move both the files
• Create a folder and inform the user that the files will be moved here
• Move both the text files within the folder.
• Inform the user about the successful execution

Build a workflow using Invoke PowerShell activity that creates two text files in the
project folder and moves both the files to a new folder. The workflow should:

• Create two text files in the project folder


• Open both the files to show their contents and close the files
• Inform the user that a folder will be created to move both the files
• Create a folder and inform the user that the files will be moved here
• Move both the text files within the folder
• Inform the user about the successful execution

Process Overview

• START
• Store a PowerShell script in a text file in the project folder that creates two text
files and stores some text in them
• Use a Read Text File activity to read the text file
• Use an Invoke PowerShell activity to run the script
• Use a Start Process activity to open and show the content of the created text files
• Use a Delay activity to allow the user some time to read the content of the files
• Use a Kill Process activity to kill the Notepad process
• Use a Message Box activity to inform the user that a folder will be created in the
project folder where both the text files will be moved
• Store a PowerShell script in a text file in the project folder that creates a folder in
the current directory
• Use an Invoke PowerShell activity to run the second script
• Use a Message Box activity to inform the user that the folder is created, and the
files will be moved

21 | P a g e
Advanced RPA Design and Development v4.0 June 2022

• Store a PowerShell script in a text file in the project folder that moves files from
the current directory to the new folder
• Use an Invoke PowerShell activity to run the third script
• Use a Message Box activity to inform the user that the files have moved
successfully
• STOP

22 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 22

Invoke VBA Activity


• Introduction to Invoke VBA Activity
• Properties of Invoke VBA Activity

This section introduces Invoke VBA activity and its properties.

23 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 23

Introduction to Invoke VBA Activity

Invoke VBA activity is used to invoke macro from an external file containing VBA code and run against an
Excel file.

• Used for Excel files with


.xls or .xlsx extensions
• Used only within an Excel
Application Scope activity

Merge the cells D3 to D10 of


SharePrice.xlsx using Invoke VBA activity

Invoke VBA activity is used to invoke macro from an external file containing VBA
code and run against an Excel file.

• It is used for Excel files with .xls or .xlsx extensions


• It can only be used within an Excel Application Scope activity

Example: Merge cells in excel file.


• Merge the cells D3 to D10 of an Excel file ‘SharePrice.xlsx.’ The Invoke VBA
activity uses the VBA code written in a script file stored locally

To know more, visit: https://docs.uipath.com/activities/docs/invoke-vba

24 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 24

Properties of Invoke VBA Activity

The properties of Invoke VBA activity are:

CodeFilePath
Enters the path to the macro file EntryMethodName
containing VBA Sub/Function Enters the Sub/Function name
definitions that is to be invoked

EntryMethodParameters OutputValue
Enters the list of up to 30 Stores the value returned by the
parameters that can be passed to execution of the invoked code
the entry method

The properties of Invoke VBA activity are:

• CodeFilePath: Enters the path to the macro file containing VBA Sub/Function
definitions
• EntryMethodParameters: Enters the list of up to 30 parameters that can be
passed to the entry method. This field supports
only IEnumerable<object> variables
• EntryMethodName: Enters the Sub/Function name that is to be invoked. Must be
present in the macro file supplied in the CodeFilePath property
• OutputValue: Stores the value returned by the execution of the invoked code if
any

To know more, visit: https://docs.uipath.com/activities/docs/invoke-vba

25 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 25

Python Activities Package


• Introduction to Python Activities Package
• Properties of Python Activities

This section introduces the Python Activities Package and properties of Python
activities.

26 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 26

Introduction to
Python Activities Package
Python activities package must be installed in Studio to run the Python code. The activities available in
the package are:

Invoke Python Method


Runs a specified method from a
Python script

Load Python Script Get Python Object


Stores the Python script handlers Converts PythonObject variable to
in a Python object a .NET datatype

Python Scope Run Python Script


Provides the scope for Python Executes the Python code directly
activities and initializes the specified or via a file
Python environment

Python activities package must be installed in Studio to run the Python code. In
Studio, the Python activities package is in UiPath.Python.Activities. The activities
available in the package are:

• Get Python Object: Converts PythonObject variable to a .NET datatype


• Invoke Python Method: Runs a specified method from a Python script
• Load Python Script: Stores the Python script handlers in a Python object
• Python Scope: Provides the scope for Python activities and initializes the
specified Python environment
• Run Python Script: Executes the Python code directly or via a file

PythonObject variable is used to store Python data.

To know more, visit: https://docs.uipath.com/activities/docs/about-the-python-


activities-pack

27 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 27

Python Activities in a Workflow

The use of Python activities in a workflow:


1
Steps:
1. Python Scope activity initializes the
Python environment 2
2. Load Python Script activity loads
the addViaPython.py file containing
Python code 3
3. Invoke Python Method activity
invokes AddTwoNumbers method
from the script
4. Get Python Object activity converts 4
the output from Invoke Python
Method into a string variable and
stores in sumResult variable
The value stored in sumResult variable
is displayed in a message box.

The use of Python activities in a workflow that adds two numbers using the Python
code:

• Python Scope activity initializes the Python environment


• Load Python Script activity loads the addViaPython.py file containing Python
code
• Invoke Python Method activity invokes AddTwoNumbers method from the script
• Get Python Object activity converts the output from Invoke Python Method into a
string variable and stores in result_Out variable

The value stored in result_Out variable is displayed in a message box.

To know more, visit: https://docs.uipath.com/activities/docs/invoking-a-python-script

28 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 28

Properties of Python Activities

Python Scope Activity Load Python Script Activity Invoke Python Method Activity

• Path: Inserts the path of the • Code: Inserts Python code to be • Input parameters: Insert
Python.exe application executed parameters to the script
• Target: Choose Python 32- or 64- • File: Choose the Python file to be • Instance: Insert the output of Load
bit versions executed Python Script activity
• Version: Choose the Python • Result: Store the output in a • Name: Insert method names from
versions variable the script
• WorkingFolder: Specifies working • Result: Store the output in a
folder of the scripts variable

The properties of Python Scope activity are:

• Path: Insert the path of the Python.exe application


• Target: Choose Python 32- or 64-bit versions
• Timeout: The amount of time to allow a Python script to run until it is terminated,
and an exception is thrown
• Version: Choose Python versions
• WorkingFolder: Specifies working folder of the scripts

To know more, visit: https://docs.uipath.com/activities/docs/python-scope

The properties of Load Python Script activity are:

• Code: Insert Python code to be executed


• File: Choose the Python file to be executed
• Result: Store the output in a variable

Note: Either the Code or the File property is needed at a time, but not both.

To know more, visit: https://docs.uipath.com/activities/docs/load-script

The properties of Invoke Python Method activity are:

• InputParameters: Insert parameters to the script


• Instance: Insert the output of Load Python Script activity

29 | P a g e
Advanced RPA Design and Development v4.0 June 2022

• Name: Insert method names from the script


• Result: Store the output in a variable

To know more, visit: https://docs.uipath.com/activities/docs/invoke-method

30 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 29

Properties of Python Activities (Contd.)

Get Python Object Activity Run Python Script Activity


• Python Object: Insert the result of • Code: Run the Python code
Invoke Python Method activity • File: Input the file path of the
• TypeArgument: Choose .NET Python code to run
datatype to which Python object is
to be converted
• Result: Store the output of the
activity in a variable

The properties of Get Python Object activity are:

• PythonObject: Insert the result of Invoke Python Method activity


• Type Argument: Choose .NET datatype to which Python object is to be converted
• Result: Store the output of the activity in a variable

The properties of Run Python Script activity are:

• Code: Run the Python code


• File: Input the file path of the Python code to run

Note: Either the Code or the File property is needed at a time, but not both

For more details, refer:


• https://docs.uipath.com/activities/docs/get-object
• https://docs.uipath.com/activities/docs/run-script

31 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 30

Classroom Exercise

Demonstrate how to use VB.NET, PowerShell, and Python


to do the following:

• Calculate the volume of a cuboid and display the output in the


output panel using VB.NET
• Sum two numbers and store the output in a Notepad file using
PowerShell
• Multiply two numbers and display the output in a message box
using Python programming language

Demonstrate how to use VB.NET, PowerShell, and Python to do the following:

• Calculate the volume of a cuboid and display the output in the output panel using
VB.NET
• Sum two numbers and store the output in a Notepad file using PowerShell
• Multiply two numbers and display the output in a message box using Python
programming language

Steps:

• Calculate the volume of a cuboid and display the output in the output panel using
VB.NET:
• In Studio, insert a Sequence activity in the designer panel
• Insert an Invoke Code activity
• Click on the Edit Arguments button
• In the Name column, enter a new argument named in_intHeight
• In the Direction column, select In
• In the Type column, select Int32. And in the Value column, enter 30 as the
default value. This value will be used in the code while calculating the
volume
• Click OK
• Click on the Edit Code button
• In the Code Editor, enter the expression:
• Dim Length, Breadth, Volume As Integer
• Length = 50
• Breadth = 20
• Volume = Length * Breadth * in_intHeight
• Console.WriteLine(“The volume of the cuboid is: {0}”, Volume)

32 | P a g e
Advanced RPA Design and Development v4.0 June 2022

• Click OK
• Save and run the workflow
• Outcome:
• Open the Output panel to see the calculated value as 30,000
• It means that the code executed successfully

• Sum two numbers and store the output in a Notepad file using PowerShell:
• Open a Notepad file and add a few lines of code that will run in PowerShell
to add two numbers
• $one = 15
• $two = 50
• $sum = $one + $two
• $output = “The total sum value is: ” + $sum
• New-Item -Path . -Name “sum.txt” -ItemType “file” -Value $output
• Save the file as SumTwoNumbers.txt
• In UiPath Studio, insert a Sequence activity
• Insert a Read Text File activity
• Click the folder icon. Select the Notepad file containing the code. Click
Open.
• Insert a new string variable Script in the Result property
• Insert an Invoke PowerShell activity below the Read Text File activity
• Insert the variable Script in the text box
• In the Properties panel of the Invoke PowerShell activity, check the box of
IsScript property
• Click on the TypeArgument dropdown and select “Browse for Types”
• Enter System.IO.FileInfo in the Type Name search bar. Select FileInfo and
click OK
• Save and run the workflow
• Outcome:
• sum.txt can be seen in the project folder
• The output is shown in the file
• It means that the code executed successfully

• Multiply two numbers and display the output in a message box using Python:
• Ensure that Python is installed on the system before running Python code
via Studio. At present, Studio only accepts Python versions from 2.7 and
3.6
• Open a Notepad file and add a few lines of code that will run in Python to
multiply two numbers
• import os
• def multiply ():
• a = 10
• b = 20
• Result = a * b
• return Result
• Save the file as multiplyTwoNumbers.py
• In Studio, insert a Sequence activity
• Install UiPath.Python.Activities package
• Insert a Python Scope activity
• Copy the file path of Python.exe from the Program directory in the C Drive

33 | P a g e
Advanced RPA Design and Development v4.0 June 2022

• In the Properties panel of the Python Scope activity, enter the copied file
path in the Path property
• In the Target property, choose 64 bits or 32 bits from the dropdown as per
your Python version
• In the Version property, choose your Python version
• Insert a Load Python Script activity in the Do section of the Python
Scope activity
• Click on the ellipsis icon and select the Python file multiplyTwoNumbers.py
• In the Properties panel, press Ctrl + K in the Result property and enter a
variable named multiplyPythonScript
• Insert an Invoke Python Method activity
• In the Properties panel, enter multiplyPythonScript in the Instance property
• Enter “multiply” in the Name property in double-quotes
• In the Result property, press Ctrl + K and enter a variable named
invokeMultiply
• Insert a Get Python Object activity
• In the Properties panel, enter invokeMultiply in the Python Object property
• In the Result property, press Ctrl + K and enter a variable named
MultipliedValue
• Insert a Message Box activity
• In the text box, enter MultipliedValue
• Save and run the workflow
• Outcome:
• A message box shows the multiplied value as 200
• It means that the code executed successfully

34 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 31

Practice Exercise

Build a workflow using Python activities to check if the


input number is a prime number. The workflow should:

• Ask the user to input a number


• Check if the number is a prime number
• Inform the user via a message box whether the number is a
prime number

Build a workflow using Python activities to check if the input number is a prime
number. The workflow should:

• Ask the user to input a number


• Check if the number is a prime number
• Inform the user via a message box whether the number is a prime number

Process Overview

• START
• Use an Input Dialog activity to ask the user to input a number
• Store the Python script to check prime numbers in the project folder
• Use a Load Python Script activity within a Python Scope activity to load the
script file
• Use an Invoke Python Method activity to call methods from the script
• Use a Get Python Script activity to convert the output from PythonObject
variable to .NET datatype
• Use a Message Box activity to display whether the number is a prime number
• STOP

35 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 32

Java and Inject JS Script Activity


• Java Activities Package
• Inject JS Script Activity

This section introduces Java and Inject JS Script activities.

36 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 33

Java Activities Package

Java activities package must be installed in Studio to run Java code. Adding the package will show the
available Java activities in the Activities panel.

Convert Java Object


Invoke Java Method
Converts JavaObject into .NET
Invokes a specified Java method
datatype

Java Scope
Create Java Object
Initializes a specified Java library
Creates a JavaObject variable
and provide a scope for Java
from a class
Activities

Get Field Load Jar


Returns a public field from a Loads a Java Library Package in a
specified JavaObject variable Java Scope activity

Java activities package must be installed in Studio to run Java code. Adding the
package, UiPath.Java.Activities will show the available Java activities in the
Activities panel. Java Activities package provides six activities to use in Studio. They
are:

• Convert Java Object: Converts JavaObject into .NET datatype


To know more, visit: https://docs.uipath.com/activities/docs/convert-java-object

• Create Java Object: Creates a JavaObject variable from a class


To know more, visit: https://docs.uipath.com/activities/docs/create-java-object

• Get Field: Returns a public field from a specified JavaObject variable


To know more, visit: https://docs.uipath.com/activities/docs/get-java-field

• Invoke Java Method: Invokes a specified Java method


To know more, visit: https://docs.uipath.com/activities/docs/invoke-java-method

• Java Scope: Initializes a specified Java library and provides scope for Java
Activities. All Java activities must run inside a Java Scope
To know more, visit: https://docs.uipath.com/activities/docs/java-scope

• Load Jar: Loads a Java Library Package in a Java Scope activity


To know more, visit: https://docs.uipath.com/activities/docs/load-jar

To know more, visit: https://docs.uipath.com/activities/docs/about-the-java-activities-


pack

37 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 34

Java Activities in a Workflow

The use of Java activities within a workflow: 1

Steps: 2
1. Java Scope activity initializes a Java
Library
2. Load Jar activity loads items.jar file 3
containing the Java Code to generate
prime numbers
3. Invoke Java Method activity runs a
static method, getPrimeNumbers, and
store the output in 4
PrimeNumbersJavaObject
4. Convert Java Object activity converts
the output from JavaObject to a .NET
array of integers named
intPrimeNumbers
The array, intPrimeNumbers, is displayed as
a string.

The use of Java activities within a workflow that generates an array of prime
numbers and displays the result as a string:

• Java Scope activity initializes a Java Library


• Load Jar activity loads items.jar file containing the Java Code to generate prime
numbers
• Invoke Java Method activity runs a static method, getPrimeNumbers, and store
the output in PrimeNumbersJavaObject
• Convert Java Object activity converts the output from JavaObject to a .NET
array of integers named intPrimeNumbers

The array, intPrimeNumbers, is displayed as a string.

38 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 35

Properties of Java Activities

Java Scope Activity Load Jar Activity Convert Java Object Activity

• Init timeout (milliseconds): Enter • JarPath: Enter the path to the .jar • JavaObject: Enter the JavaObject
the Amount of time to wait for Java file containing the Java Library variable to be converted to .NET
runtime connection Package data type
• JavaLibraryPath: Enter the path to • TypeArgument: Select .NET data
the Java executable java.exe file type
• Result: Store the converted
JavaObject stored in a .NET variable

The property of Java Scope activity is:

• JavaLibraryPath: Enter the path to the Java executable java.exe file


To know more, visit: https://docs.uipath.com/activities/docs/java-scope

The property of Load Jar activity is:

• JarPath: Enter the path to the .jar file containing the Java Library Package
To know more, visit: https://docs.uipath.com/activities/docs/load-jar

The properties of Convert Java Object activity are:

• JavaObject: Enter the JavaObject variable to be converted to .NET data type


• TypeArgument: Select .NET data type
• Result: Store the converted JavaObject stored in a .NET variable

For more details, visit: https://docs.uipath.com/activities/docs/convert-java-object

39 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 36

Properties of
Java Activities (Contd.)

Get Field Activity Create Java Object Activity Invoke Java Method Activity

• FieldName: Return name of the • Parameters: Pass arguments to • MethodName: Pass name of the
field as JavaObject variable Java method method to be invoked
• Result: Store Java field in a • ParametersList: List of parameters • Parameters: Pass arguments to a
JavaObject variable to pass to a Java method Java method
• TargetObject: Retrieve JavaObject • Result: Store output in JavaObject • TargetObject: Enter name of Java
containing the field variable Package on which to execute Java
• TargetType: Use the Java class • TargetType: Use the Java class method
name to create JavaObject name to create JavaObject • TargetType: Enter Java package
name class

The properties of the Get Field activity are:

• FieldName: Return name of the field as JavaObject variable


• Result: Store Java field in a JavaObject variable
• TargetObject: Retrieve JavaObject containing the field
• TargetType: Use the Java class name to create JavaObject

To know more, visit: https://docs.uipath.com/activities/docs/get-java-field

The properties of Create Java Object activity are:

• Parameters: Pass arguments to Java method


• ParametersList: List of parameters to pass to a Java method
• Result: Store output in JavaObject variable
• TargetType: Use the Java class name to create JavaObject

To know more, visit: https://docs.uipath.com/activities/docs/create-java-object

The properties of Invoke Java Method activity are:

• MethodName: Pass name of the method to be invoked


• Parameters: Pass arguments to a Java method
• ParametersList: Pass list of parameters to a Java method
• Result: Store output stored in JavaObject variable
• TargetObject: Enter name of Java Package on which to execute Java method
• TargetType: Enter the Java package name class

For more details, visit: https://docs.uipath.com/activities/docs/invoke-java-method

40 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 37

Inject JS Script Activity

Used to execute the JavaScript code in Studio. It executes JavaScript code in the context of the web page
corresponding to a UiElement.

Run the workflow in Studio


to display a popup in the
browser

Inject JS Script activity is used to execute the JavaScript code in Studio. It executes
JavaScript code in the context of the web page corresponding to a UiElement.

Example: Run the workflow in Studio to display a popup in the browser


• Input Dialog activity takes in the input to be displayed in the popup box. Open
Browser activity opens the specified URL. Then, the Inject JS Script activity runs
the JavaScript code provided in the example.js file

To know more, visit: https://docs.uipath.com/activities/docs/inject-js-script

41 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 38

Properties of
Inject JS Script Activity
The properties of Inject JS Script activity are:

Element
InputParameter
Returns the UiElement variable by
Inputs the data for JavaScript code
another activity

Selector
ScriptCode
Uses text property to find a UI
Runs the JavaScript code as a
element
string or full path to a .js file

Timeout (milliseconds)
ClippingRegion Specifies the amount of time to wait
Defines the clipping rectangle in for the activity to run
pixels
WaitForReady
Waits for the target to become
ready. The following options are
available: None, Interactive,
Complete

The properties of Inject JS Script activity are:

• InputParameter: Inputs the data for JavaScript code


• ScriptCode: Runs the JavaScript code as a string or full path to a .js file
• ClippingRegion: Defines the clipping rectangle in pixels
• ScriptOutput: Returns the string result from JavaScript code
• Element: Returns UiElement variable by another activity
• Selector: Uses text property to find a UI element
• Timeout (milliseconds): Specifies the amount of time to wait for the activity to
run
• WaitForReady: Waits for the target to become ready. The following options are
available: None, Interactive, Complete

To know more, visit: https://docs.uipath.com/activities/docs/inject-js-script

42 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 39

Best Practices
• Best Practices for Utilizing External Code

This section gives an overview of the best practices for utilizing external code.

43 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 40

Best Practices

The best practices for utilizing external code are:

Use Invoke Code activity to combine multiple Assign and Invoke Method activities

Use Invoke VBA activity if the goal is to handle Excel files only

Keep all script files within the project folder only

Always check if there are equivalent out-of-the-box activities to run the logic in external code

Invoke code with multiple lines of code is a complex solution for long-term maintenance of the projects

The best practices for utilizing external code are:


• Use Invoke Code activity to combine multiple Assign and Invoke Method activities
• Use Invoke VBA activity if the goal is to handle Excel files only
• Keep all script files within the project folder only, if possible
• Always check if there are equivalent out-of-the-box activities to run the logic in
external code
• Invoke code with multiple lines of code is a complex solution for long-term
maintenance of the projects

44 | P a g e
Advanced RPA Design and Development v4.0 June 2022

Slide 41

Summary

01 Invoke Method Activity

02 Invoke Code Activity

03 Invoke PowerShell Activity

04 Invoke VBA Activity

05 Python Activities Package

06 Java and JS Script Activity

To summarize, this lesson explained:


• Invoke Method Activity
• Invoke Code Activity
• Invoke PowerShell Activity
• Invoke VBA Activity
• Python Activities Package
• Java and JS Script Activity

45 | P a g e

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy