Views:

## Overview

An important principle of rule engines is chaining. This is where the action part of one rule changes the system state in a manner that it alters the input value of the condition part of other rules. Chaining can be tricky to get right as a lot of rules engines tend to decompose rules at a very fine level of granularity which makes it very difficult to manage and stop becoming Spaghetti Rules.

The North52 approach here is to ask the question 'Is the business problem I'm trying to solve Tightly or Loosely coupled?' If tightly coupled then it is best to use what we call a Multi-Sheet Decision Table. This makes the whole approach of solving the business problem very natural and you do not really think about what rules need chaining together.

## Tightly Coupled - Multi-Sheet Decision Table

Multi-Sheet Decision Tables are great to use when you have a business problem that is very much related to itself. A good example of this is where you are trying to calculate the risk score for Coronary Heart Disease. This business problem can be decomposed into multiple rules but they are all tightly coupled risk factors. This type of Formula executes Decision Tables one sheet at a time from left to right. And within each sheet from left to right and then down. This makes the whole chaining process natural as it "Just Works" and should be fairly obvious to users with little or no training.

The knowledge base article Multi-Sheet Decision Tables introduces the core principles.

## Loosely Coupled - Single Sheet Decision Table

We could of course have used a single Decision Table for each Risk Factor and Calculation and we would have ended up with 10 Formulas/Rules. The Risk Core Decision Table would then have used the ExecuteFormula function call to gather the results and then calculate its score.

There is the extra overhead of having to manage these 10 Formulas/Rules as a type of ruleset. However, this is easily done by using the Category and Sub-Category fields on the Formula. The knowledge base article How To - Categorization of Formulas discusses how to do this.

Executing individual Formulas for each risk result:

Using the results of each executed Formula to calculate the Risk Score:

## Deployment of Formulas/Rulesets

A set of North52 Formulas/Ruleset can be deployed via a normal Dynamics 365 solution. This provides an extra layer of Categorization if needed but typically we see the Category field on the Formula matching the Deployment Solution. The Deployment of North52 Solutions article provides a good introduction.

## Execution Order

North52 BPA is deeply integrated with the Dynamics 365 Event Framework and so sometimes you may need control the execution order of formulas within one of the Microsoft events:

• PreValidation
• PreOperation
• PostOperation

In order to do this each Formula has its own Execution Order field which is an integer number which can be set to control the order in which North52 server-side or client-side Formulas execute.