UiPath Custom Rules
Engine Activity Tutorial - Part 2
In this tutorial, you create a UiPath workflow application for a fictitious
online lender. It determines whether a customer is eligible for a loan
according to specific criteria (rules). The criteria include the amount of the
loan, the annual income of the borrower, and the duration of the loan.
To make the workflow, we will not follow the typical rule development
workflow (so many if-else conditions ..) We will use the custom rules engine.
By doing so, you discover the steps required to develop, deploy, and maintain a
rule-based application.
Prerequisites:
·
UiPath Studio <=
2022.4.6
·
UiPath Robot <= 2022.4.6
·
Orchestrator (will use
staging)
·
Data Service
·
Insights
·
Internet Access to download
the package
Rules
Initially, we have the following policy (business rules) to apply for a loan
( 8 rules). Please note the priority for each one.
If you don’t want to follow along you can download the code from the last
section, Source.
Procedures
1.
Create two entities that
represent the business object models in data service (Borrower and Loan) as per
the images below or import the attached schema file in the last section to
generate the entities.:
2. Create a UiPath Studio Project (C#, Windows)
3. Import package UiPathTeam.RulesEngine.Activities
4.Import the business entities(borrower and loan)
I’ll use OnlineBanking.Models as namespace.
5. From Activities Panel >> UiPathTeam.RulesEngine.Activities
>> Drag Rules Activity Panel >> In Select Type Dialog Choose (OnlineBanking.Models.Loan)
6. After clicking ok in step 5, you will see the
rule policy activity as in this image (Rule Policy), where you need to fill in
the following:
Rule File Path: click on the
ellipse icon and choose any location the dialog will create the file if it’s
not exists.
Rule SetName: click on RuleSet
Browser to create a group
Target Object: I created a
variable of type OnlineBanking.Models.Loan to pass it to the
rules engine
Result Object: same as
TargetObject value
7. Click Edit Rules to start adding the rules,
after adding all rules, you should get this view:
“Please note I’m using the Halt keyword in Rule 8
to end the execution if loan amount > 1M”
Your .rules file should contains the XAML representation
of your code:
<RuleDefinitions.RuleSets>
<RuleSet Description="{p3:Null}" Name="Loan-1-0" ChainingBehavior="Full" xmlns:p3="http://schemas.microsoft.com/winfx/2006/xaml">
<RuleSet.Rules>
<Rule Priority="1" ReevaluationBehavior="Never" Description="{p3:Null}" Active="True" Name="Rule 8">
<Rule.Condition>
<RuleExpressionCondition Name="{p3:Null}">
<RuleExpressionCondition.Expression>
<ns0:CodeBinaryOperatorExpression Operator="GreaterThan"xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089">
<ns0:CodeBinaryOperatorExpression.Right>
<ns0:CodePrimitiveExpression>
<ns0:CodePrimitiveExpression.Value>
<ns1:Int32 xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">1000000</ns1:Int32>
</ns0:CodePrimitiveExpression.Value>
</ns0:CodePrimitiveExpression>
</ns0:CodeBinaryOperatorExpression.Right>
In workflow I used custom logs activity to measure the processing time for each loan request.
I’ll use Insights’ s dashboard as a reporting for processing time so we can compare the
performance of the custom activity (Rules Engine) with any other way like if-else activities.
Custom Log Filed:
· RulesEngineTransacionTimeMilliseconds
· RulesEngineEntityId
· RulesEngineEntityIsApproved
Testing
To test our policy I’ll do the following:
1.
Read all Loan records as
sets (100 records per set) with condition IsProcessing = false
2.
Loop over each set and
apply rules policy to get the result
3.
Update loan entity so we
don’t read the record again.
4.
To fill data service with
test data, run the GenerateTestData workflow, where it will
create random data based on the DataSize argument value (there
are 8 names in the workflow and the DataSize argument adjust
the number of loans per name)
5.
Publish the package (Online.Banking)
to your Orchestrator
6.
Grant your Robot account a
read and write permission on data service
7.
Create a process to fill
data; set Entry point to GenerateTestData and
display name to Online.Banking.GenerateData
8.
Create a process to test
the rules engine; set Entry point to Main and
display name to Online.Banking.Loan
after setting the configuration you should get this view in your
orchestrator
Performance:
This graph (from Insights) shows the average processing time per loan in
Milliseconds using a 48,523 Records.
Source:
https://github.com/ajamaeen/UiPath-Rules-Engin-Samples
Schema file for Data Service Entities :https://github.com/ajamaeen/UiPath-Rules-Engin-Samples/blob/main/Docs/Schema.json
NuGet Package: https://github.com/ajamaeen/UiPath-Rules-Engin-Samples/releases/tag/UiPathRulesEngine
No comments:
Post a Comment