How To Use Invoke Code Activity – In UiPath

As the process becomes a little complex, we might want to write our own code as per the requirement.

More customization is possible in Uipath by using VB.Net.

We have an activity to achieve the above, let’s see how to use it…!!!

Example

Implementation using UiPath :

Let us implement a workflow which takes a sample data table as input and outputs the SUM of total sales.

Step 1:
Drag “Build Data Table” activity into the design panel and populate it with sample data.

UiPath Invoke Code Activity Example 1UiPath Invoke Code Activity Example 2

Step 2:
Drag “Invoke Code” activity into the design panel.

UiPath Invoke Code Activity Example 6.PNG

Step 3:
In “Invoke Code” activity, click “Edit Arguments” option to pass the required parameters as below.

Note:
Sample_DT is our DataTable (IN Argument)
Sum is the summation result (OUT Argument)

UiPath Invoke Code Activity Example 3.PNG

Step 4:
In “Invoke Code” activity, click Code” option to write the execution code.

Note:
Below code is used to count the total sales of all the divisions

Dim row As DataRow
sum=0
For Each row In Sample_Dt.Rows
sum= cInt(row(“Sales Amount”).toString)+Sum
Next row

UiPath Invoke Code Activity Example 4.PNG

Step 5:
Drag “Message Box” activity into the design panel and pass the “Sum” value into it.

UiPath Invoke Code Activity Example 5.PNG

Step 6:
Finally, let’s run the project.
Now, we can see total sales value being displayed.

UiPath Invoke Code Activity Example 7

Click here to download the Source Code…

Hope it has helped you… 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: