Custom Functions in Microsoft Business Rules Engine
The Microsoft Business Rules Engine (BRE), part of Microsoft BizTalk Server, allows for the creation of rich easily readable business rules which can be applied by a BizTalk solution, or any .NET code. Out of the box, BRE and the main interface Business Rules Composer (BRC) have many different predicates that can be used within a rule, such as Equal, Less Than, Range, Greater Than, Not Equal, Between, and so on. However, when creating a set of rules for a client, I realized that simple string functions that are not available ‘Out of the Box’ in the BRC. I decided to create a .NET class which will contain a collection of string functions for use within business rules.
The first step in creating custom functions that can be called within business rules is to create a .NET assembly project with a static class and all of the public methods for the functions you would like to call.
Make sure that the assembly is added to the GAC, and open up BRC. In BRC, create a new policy and within the Fact Explorer browse to your .NET class in the GAC.
BREFunctions is the class I have created that contains my custom functions. The policy that I have created for this is “_myPolicy” and the rule that I have created to demonstrate my custom functions is “”myRule”.
Dragging the Trim function from my BREFunctions class to the left hand equal to operand of my IF window adds the function to the rule. The left hand operand equals ‘” hasextraspaces “ my right hand operand equals “hasextraspaces”. The exists statement is included to facilitate testing my function with an XML document instance.
In testing my rule, I passed in an instance of my test X12EnrichedMessage, and received the following output.
As can be seen above, the static class was not executed. This is because by default, static classes cannot be executed without specifying an instance of our static class. However, we can bypass this by specifying the “StaticSupport” registry DWORD =1. To do this, navigate to the following registry entries:
If the StaticSupport DWORD does not exist, create it and set its decimal value to 1. If it does exist, set the decimal value from 0 to 1.
Now retesting my XML instance, we can see that the TRIM custom function was executed successfully.