Creating Custom Rule Verbs Using Rule Engine Extension

Last Updated: 12/12/2018 Introduced in Version: 5.0

This tutorial demonstrates how to use a Rule Engine Extension to evaluate Rule Flow behavior using custom verbs. The Flow 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. 

 

Example:

Begin in the designer Folder by selecting Create Flow on the Folder Actions Panel and Name the Flow. In the Properties Tab in the Settings section under Behavior Type select Rule Engine Extension to set the Flow behavior. Proceed to the Flow Designer and begin building the Flow (Figure 1).

 

Figure 1

 

Steps: Location

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

 

Flow Example

Creating Custom Rule Verbs Using Rule Engine Extension, (Figure 2)

Figure 2

Start Step

In the Flow Data section under Flow Input Data select Show Editor to add a Data Definition. Create a Name and define its Type as String. To save and exit select Close (Figure 3).

Name: Emailaddress

Type: String

 

Figure 3

 

 

Fetch Entities Step (Fetch Account by Email Address)

In the Entity Fetch Definition under Type Name select [Account] Decisions Framework. Under Fetch Criteria select Add New, to add a data definition (Figure 4).

*Note: select the pencil icon to edit Fetch Criteria.

Field Name: emailAddress

Query Match Type: Equals

Figure 4

 

 

Create Data Step: Set Output Boolean to TRUE, (Figure 5).

Name: output

Type: Boolean

Figure 5

 

In the Inputs section set the output to Constant and check the box to run the rule as TRUE (Figure 6).

Figure 6

 

Create Data Step: Set Output to FALSE, (Figure 7).

Name: output

Output: Boolean

Figure 7

 

In the Inputs section set the output to Constant and uncheck the box to run the rule as FALSE, (Figure 8).

Figure 8

End Step

On the End Step in the Data section under Output select Show Editor and create a data definition. Create a Name (Result) and choose the Type (Boolean). In the Inputs section next to Result choose Select From Flow and Pick output, (Figure 9).

Name: Result

Type: Boolean

Figure 9

 

After the Steps are configured in the Properties Tab under Common Properties, connect the pathways as displayed in (Figure 2). Complete the flow by selecting Debug and verify that the flow works properly. This completes the Creating Custom Verbs Using Rule Engine Extension, save and close Flow Designer.

 

Create Rule

The Flow can now be evaluated using a Rule. Start by creating a Rule in the designer Folder to test the Custom Verb created above. Test the Rule 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. Select Close to save and exit, (Figure 10).

 

Figure 10

 

Create the Rule Phrase that will evaluate the Rule Engine. Pick [Select Data Element] and choose CompanyName, next select [Pick Verb] and expand the Evaluate category and choose isCustomerInDatabase. Leave [no parameters] as is and complete the rule (Figure 11).

Figure 11

 

 

 

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, (Figure 12).

Figure 12

 

Under Rule Example Data, select Add New. In the Add Unit Test area, add an existing Company Name from the database, name the Unit Test (Pass) and expect it to Pass. Then, select Save, (Figure 13).

Figure 13

 

 

Now Create a new Unit Test, select Add New. Name the unit test (Fail) and expect the Rule to Fail. To test the Unit 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, (Figure 14).

 

Figure 14

 

 

Test the Rule and Run All Unit Tests. The results should verify that both Unit Tests executed as expected (firs-Passes, second -Fails), (Figure 15).

Figure 15

 

Links:

About Flow behaviors

Creating your first rule

Additional Resources