Rule Extensions Using Rule Engine

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

This tutorial demonstrates how to use Rule Extensions in Rule Engine. Rule Engine Extension is a Rule Behavior implemented in Decisions 3.2. This Rule Behavior allows to create a Rule that can be embedded in another Rule. It is required to add “anchor” Input in the “Main” Rule in order to use Rule Engine Extension. This “anchor” Input should be the same Type of Data that Extension Rule has as its Rule Input Data.

 

Example:

In this example we will create a Flow that should validate if the Account in the Portal belongs to the Decisions Employee, and then, display all Accounts that passed this validation. In order for the Account to pass validation it should contain decisions.com in the Email Address field. Additionally, it should have a specific Address in the Contact Info. Because Address is a complex Data Type, we will create a Rule Extension that will check if the Address is valid for the Account.

First, we need to create a Complex Address Data Structure. In the Designer Folder we select Create Datatypes > Defined Data Structure [Advanced] option from Folder Actions.

 addDefinedDataStructure

We name it Address and add four Data Members. Click Ok to save and close Add DefinedDataStructures window.

 dataStructDefinition

Next, we are going to create our Extension Rule. In the Designer Folder we click Create Rule > Create Rule on the Folder Actions Panel.

 createExtensionRule

In the resulting pop-up window we Name our Rule and select Rule Engine Extension from Behavior dropdown. Click Create to proceed to the Rule Designer.

 nameRule

In the Rule Designer we click Add New link to add new Rule Input Data.

 addNewRuleInputExtension

In the Add Rule Input Data pop-up window we Name our Input and select Address Data Structure that we have created for this tutorial as its Type. Click Ok to save and continue.

 defineRuleInputDataEx

Back in the Start Rule Wizard we click Add New Rule Step…

 addNewRuleStepEx

In the Rule Phrase Builder we expand Address Rule Input, select City Data Member and click Next.

 addressCity

Then, we expand Equals Verb category select Is and click Next.

 addressCityIs

Finally, we define Constant City Value for our Address and click Done to complete this Phrase.

 cityConstant

In the Resulting pop-up window we click Add New Rule Step to create another Rule Phrase for different Data Member in the Address Input Data.

 addNewRuleStepSecond

In the similar manner we add Rule Phrases for each of the Data Members in the Address Data Structure. When completed our Rule should look as following. It will accept Address Data and return True if all Data Members match our desirable Address. We can save the Rule and close Rule Designer.

 RuleExtensionComplete

Next, we will create our Main Rule that will use Extension Rule. In the Designer Folder we click Create Rule > Create Rule.

 addSecondRule

Then, Name the Rule and click Create to proceed to the Rule Designer.

 nameSecondRule

In the Rule Designer we Add New Rule Input Data…

 addNewInputSecond

We Name our Rule Input Data. This Rule Input Data have to be the same Type as Input Data for our Extension Rule. We select Address Type. In this case this Rule Input Data will be an “anchor” for our Extension Rule. Click Ok to save and continue.

 addAddressInputSecond

Back in the Start Rule Wizard we click Add New link to add another Rule Input Data.

 addSecondInputMainRule

Our second input will be of type Account.

 secondInputMainRule

Back in the Start Rule Wizard we click Add New Rule Step to start designing our Rule.

 addFirstStepMainRule

In the Phrase Builder we select our AccountAddressanchorInput Data and click Next.

 pickAccAddress

Next, in the verb definition window we expand Rule Engine Extensions and pick our Extension Rule as a verb for this Rule Phrase. Click Next to continue.

 pickDecisionsAddressRule

Our Extension Rule does not take any additional Input Parameters, therefore we click Done to complete this Rule Phrase.

 doneFirstStep

Next, we click Add New Rule Step to add new Phrase.

 addSecondStepMainRule

This time we expand Account Input Data and select EmailAddress field. Click Next to continue.

 pickEmailAddress

In the Verb definition we select Contains from the Text Rules category. And, click Next

 textContains

This Rule Phrase should validate that Account’s Email Address contains decisions.com. We define this string as a Constant Value and click Done.

 constantEmailString

This completes our Rule Design.

 closeMainRuleWiz

The Rule should look as following. Then, we can save the Rule and close Rule Designer.

 ruleMainCompleted

Back in the Designer Folder we click Create Flow on Folder Actions Panel.

 createFlow

Next, we Name the Flow and click Create to proceed to the Flow Designer.

 nameFlow

In the Flow Designer we add Get All step from Integrations > All Integrations > Internal Service > Account Service category in the Flow Designer Wizard.

 getAllAccounts

To iterate through the collection of All Accounts we add ForEach Step from All Steps [Catalog] > Flow Management category in the Flow Designer Wizard.

 addForEach

In the resulting pop-up window we select GetAll_Output collection and click Add.

 addCollectionForEach

On the Next Outcome from the ForEach Step we add GetAddressForContactInfo step from Integrations > All Integrations > Internal Services > Address Service category in the Flow Designer Wizard.

 addGetAddressForContactInfo

Then, we add our Validate Decisions Employee Rule from Flows, Rules, Forms and Reports > Rules > [Current Folder] category.

 addRuleToFlow

Next, we connect False outcome from the Rule step back to the ForEach Step, and select Show Mapping Editor from GetAddressForContactInfo step Options.

 showMappingForGetAddress

In the Mapping Editor we expand Item outcome from the ForEach Step and connect AccountID Data Member to the contactInfoId field. Then, save and close Mapping Editor.

 mappingForGetAddress

Back in the Flow Designer we call Mapping Editor for our Rule Step in the Flow.

 showMappingForRule

We connect Item outcome from the ForEach Step to the Account Data Input in our Rule. Then, we use Build Data Mapping type for the Address field.

 buildDataForAddress

We expand GetAddressForContactInfo_Output and connect respective fields to the Address Data Members. Click Ok to save and close Mapping Editor.

 mappingForRule

Back in the Flow Designer we drag and drop into the workspace Add Item To List step from Data > List category in the ToolBox.

 dragAddItemToList

We connect this step to the True outcome from the Rule step in our Flow. Then, we connect Done outcome from this step back to the ForEach Step, and select Show Mapping Editor Option for this step.

 showMappingForAddItem

Data Mapping for this step should look as following…

 mappingForAddItem

In order for the New List to be Account [] Type we need to change ListType option for this Step.

 listType

Finally, we drag and drop Show Form step from Favorite Steps category in the ToolBox.

 addShowFormStep

On the workspace we connect Show Form step to the Done outcome from the ForEach Step, and select Pick or Create Form from the step Options.

 pickOrCreateForm

In the resulting pop-up window we Name our Form and click Create to proceed to the Form Designer.

 nameForm

This Form designed as following. It has several Label components from Data category to display Title and additional information. Next, it has a Button control from Actions category. Finally, we use Data Grid component from the List category and configure this component to display a List of Accounts. We keep desirable fields to display from the Account Data Type. When finished, we can save and close Form Designer.

 formDesign

Back in the Flow Designer, we connect our Form step to the End Step in the Flow. Next, we call Mapping Editor for the Show Form step.

 showMappingForForm

In the Mapping Editor we simply connect a New List of the validated Accounts to the DecisionsEmployees Data Grid component on our Form. Then, save and close Mapping Editor.

 mappingForForm

This completes our Flow. We click Debug Flow link on the Top Panel in the Flow Designer to test our Flow.

Note that in Decisions version 3.5 and higher, you’ll need to click on Test Flow to access the Debugger.

3.5 Test Flow Shot

 debugFlow

Our Form opens in the Debugger displaying a List of validated Accounts. We click Done on the Form.

 formInDebugger

Diagram Tab in the Debugger indicates that our Flow was executed with no errors.

 flowRanWithNoIssues

If we check Contact Info for the validated Accounts from our Flow

 AccountContactInfo

We can confirm that they have the same Address that we used in our Extension Rule for validation.

 

 addressInContactInfo

 

 

 

 

Additional Resources