Creating Custom Rule Verbs Using Rule Engine Extension
- Updated on 05 Mar 2019
- 3 minutes to read
This tutorial demonstrates how to use a Rule Engine Extension to evaluate Rule Flow behavior using custom verbs. TheFlow Behavior Type is used to create a custom verb for Rules with a Flow. This type of Flow can have an Input and has to Output either a True or False Boolean Type. In this demonstration, the Rule Engine Extension Flow behavior is used to create (emailaddressisinlist) verb for the Rule Engine . The Flow will have String Input (emailaddress), then it will query Decisions Accounts and check if the emailaddress Input matches any of the records in the email address accounts.
Begin in thedesigner Folder by selecting Create Flow on the Folder Actions Panel and Name the Flow. In the Properties Tab in theSettings section under Behavior Type select Rule Engine Extension to set the Flow behavior. Proceed to the Flow Designer and begin building the Flow .
- Start Step (Email Address in) : Located in the Flow designer
- Fetch Entities (Fetch Account by Email Address): Integrations > My Integrations > Databases > Mock Data (Database) > dbo.person (Table)
- Create Data (Set Output Boolean to TRUE): Data>Create Data Step
- Create Data (Set Output Boolean to FALSE): Data> Create Data Step
- End Step (Resul Boolean): Located in the Flow designer
In the Flow Data section underFlow Input Data select Show Editor to add aData Definition. Create a Name and define its Type as String. To save and exit selectClose.
- Name : Emailaddress
- Type: String
Fetch Entities Step (Fetch Account by Email Address)
In theEntity Fetch Definition under Type Name select [Account] DecisionsFramework. UnderFetch Criteria selectAdd New , to add a data definition (Figure 4).
*Note: select the pencil icon to edit Fetch Criteria.
- Field Name: emailAddress
- Query Match Type : Equals
Create Data Step: Set Output Boolean to TRUE
- Name: output
- Type: Boolean
In the Inputs section set the output to Constant and check the box to run the rule as TRUE
Create Data Step: Set Output to FALSE
- Name: output
- Output: Boolean
In the Inputs section set the output toConstant and uncheck the box to run the rule asFALSE, (Figure 8).
On the End Step in the Data section under Output select Show Editor and create a data definition. Create aName (Result) and choose the Type (Boolean). In the Inputs section next toResult choose Select From Flow and Pick output.
- Name : Result
- Type: Boolean
After the Steps are configured in the Properties Tab under Common Properties, connect the pathway. Complete the flow by selecting Debug and verify that the flow works properly. T his completes the Creating Custom Verbs Using Rule Engine Extension, save and close Flow Designer.
The Flow can now be evaluated using aRule . Start by creating a Rule in the designer Folder to test the Custom Verb created above. Test theRule Engine Extension using a Rule. Select Create Rule > Create Rule from the Folder Actions Panel. When the Rule designer opens in the Rule Data section select Show Editor to add Rule Input Data . Then Name the input and define its Type as String . SelectClose to save and exit.
Create the Rule Phrase that will evaluate the Rule Engine. Pick [Select Data Element] and choose CompanyName, next select [Pick Verb] and expand theEvaluate category and choose isCustomerInDatabase. Leave**[no parameters]** as is and complete the rule.
This completes the Rule design . Next, create Unit Tests for this Rule . On the top panel of the rule designer select Debug to debug the rule.
Under Rule Example Data, select Add New. In theAdd Unit Test area, add an existing Company Name from the database , name the Unit Test (Pass) and expect it to Pass . Then, select Save.
Now Create a new Unit Test , select Add New . Name the unit test (Fail) and expect the Rule to Fail. To test theUnit Test Rule use a company name that does not exist in the database. This example uses the name (The Famous Company) . and as CompanyName input we use a CompanyName that does not exist in our database . Click Save.
Test the Rule and Run All Unit Tests. The results should verify that both Unit Tests executed as expected (firs-Passes, second -Fails).