Rule Engine Extension / Evaluate Rule Flow Behavior

Last Updated: 07/15/2016 Introduced in Verision: 2.0

This tutorial demonstrates how to use Rule Engine Extension / Evaluate Rule Flow behavior. This Flow Behavior type is used to expose Flow as a Verb for the Rule Engine. In other words, we can create a custom verb for Rules with a Flow. This type of Flow can have an input and has to output either True or False Boolean value.



In this example we will use Rule Engine Extension / Evaluate Rule Flow behavior to create isCustomerInDatabase verb for the Rule Engine. Our Flow will have a String input (Company Name), then it will query a database table (an integration with External Database Table is out of this tutorial scope), and finally, it will check if Company Name input matches any of the records in database.

We begin in the Designer Folder with clicking Create Flow button on the Folder Actions Panel.


Then, we Name our Flow (this Name will be the Name of the verb in the Rule Engine). Next, from the Behavior dropdown list we select Rule Engine Extension / Evaluate Rule Flow type. Click Create to proceed to the Flow Designer.


 In the Flow Designer we select Start Step on the workspace and Step Information Layer pops up. In the Flow Input Data we click Add New link. Then, we provide Name for the Flow Input Data and define its Type as String. Click Create to save and continue.


After Flow Input Data configured we can click Add Step to start building our Flow.


First, we will create a Variable in our Flow that will hold the Boolean Result for the Flow Output. We add Create Data step from the Favorite Steps category.


In the Data Definitions pop-up window we click Add New.


Then, we Name our Data Definition ‘Result’ and define its Type Boolean. Click Ok to save and continue.


When we finished defining Data we can click Add.


Next to the Create Data step in our Flow we add Get All From dbo.Customers step from Integrations > My Integrations > Databases > Northwind (Database) > dbo.Customers (Table) category.


Next, we select our Create Data (Result) and define its Value as Constant False (we will change this value to True only in the case if our Input Company Name is found in the Database).


Next, we select Get All From dbo.Customers step on the workspace and on the False outcome we add Throw Exception step from the All Steps [Catalog] > Flow Management category.


In the resulting Throw Exception configurations window we define Constant message for the Exception. Our Flow will be executed on this Path only in the case when our query to the database Fails, not if nothing is found in the Table.


Then, we select Get All From dbo.Customers step on the workspace and configure to Ignore Limit count Input to this step.


Next, on the Done outcome from the Get All From dbo.Customers step we add String Is in List step from All Steps [Catalog] > Data > Text category.


We select this step on the workspace to Configure it. Mention, that this step is a Rule like step and it has True and False outcomes which is not quite fits our needs. In the step configurations we expand Outcomes category and uncheck Expose Step as a Rule checkbox. Now our step will have one outcome Path (Done) and will output either True or False Value.


Then, we click Show Mapping Editor for this step to configure the rest of Data.


In the Mapping Editor in the Inputs section (left side of the Mapping Editor) we define caseInsensetive field as Constant False. Then, we connect our Company Name Flow data Input to the Value field. Next, we expand Customers_Result category (outcome from Get All From dbo.Customers step) and connect CompanyName collection to the List field. In the right side of the Mapping Editor (Output from section) we change the Value of our Create Data Boolean Result with the Outcome from this step. When finished, we can save and close Mapping Editor.


Then, we connect the Outcome from the String Is in List step to the End Step in our Flow. Select End Step and configure it as following…  For the Result Input we Select Value of Result Variable that we created at the beginning of our Flow with Create Data step.


This completes our Evaluate Rule Flow. We can save and close Flow Designer.


Back in the Designer Folder we will create a Rule to test Custom Verb that we just created. Click Create Rule > Create Rule from the Folder Actions Panel.


In the resulting window we Name the Rule and click Create to proceed to the Rule Designer.


When Rule Designer opens, we click Add New to add Rule Input Data. Then, we Name the input and define its Type as String. Click Ok.


After Rule Input Data is added we click Add New Rule Step button.


In the resulting window we pick CompanyName Rule input and click Next.


In the verb definition window we expand Evaluate category and pick isCustomerInDatabase verb that we created using Rule Engine Extension / Rule Evaluation Flow in this tutorial. Click Next.


In the parameters window we click Done.


Then, we Close Rule Phrase Builder.


This completes our Rule Design. Next, we are going to create Unit Tests for this Rule. On the top panel of the Rule Designer we click Debug Rule.

Note that in Decisions version 3.5, you’ll need to click on Unit Test to access this function.

3.5 Unit Test Rule Shot


In the resulting pop-up window we use an existing Company Name from the database, name Unit test Pass and expect it to Pass. Then, click Save.


Next, in the Run Unit Tests window we Create New Unit Test. Name it Fail, expect the Rule to Fail, and as CompanyName input we use a CompanyName that does not exist in our database. Click Save.


Then, we Run All Unit Tests


As a result, both our Unit Tests executes as we expected (first – Passes, second – Fails).


Additional Resources