Geeks With Blogs
Evan Koch Musings on BizTalk Server and SQL Server
It’s useful from time to time to be able to call external functions within business rules.  Instead of something like this:

We can make calls to external functions in business rules like this:

The IsOpenEnd function is below.  The return type is already a Boolean so it’s unnecessary to check to see if the returned value is equal to true or not.

        public static Boolean IsOpenEnd(int loanTypeCd)

        {

            if ((loanTypeCd == LoanTypeCode.HomeEquityLineOfCredit) || (loanTypeCd == LoanTypeCode.HomeEquityLineOfCreditPurchaseMoney))

                return true;

            else

                return false;

        }

Similarly, I can simplify a ClosedEndCreditType rule.

        public static Boolean IsClosedEnd(int loanTypeCd)

        {

            if ((loanTypeCd == LoanTypeCode.HomeEquityLoan) || (loanTypeCd == LoanTypeCode.HomeEquityLoanPurchaseMoney))

                return true;

            else

                return false;

        }

You can also use external functions to perform parsing on a value within the rule.  For instance, imagine a situation where the value of the branch within the source XML is prefixed with a five character code.  One might find the following useful in that situation:

        public static string ParseBranchNumber(string branchNumber)

        {

            return branchNumber.Substring(5, 5);

        }

It’s important to note that all the functions are static.  If the functions are not static, one would have to implement a Fact Creator and reference it when testing the rules or create an instance of the class when calling rules from an orchestration or other source.  For static methods to work, however, static support must be enabled for the Business Rules Engine.

Invoking Static Members of a Class

By default, the rule engine requires you to assert an instance of a .NET class to execute a policy that invokes a static member of the .NET class. You can modify this behavior by changing the value of the StaticSupport registry key under HKEY_LOCAL_MACHINE\Software\Microsoft\BusinessRules\3.0 to one of the values in the following table.

StaticSupport registry value

Rule engine behavior

0

Default value. The rule engine follows the BizTalk Server 2004 model, where the static method is called only when an instance of the .NET class is asserted.

1

An object instance is not required. The static method is called when the rule is evaluated or executed.

2

An object instance is not required. The static method is called at the policy translation time if all parameters are constant. This is a performance optimization because the static method is called only once even though it is used in multiple rules in conditions. Note that static methods used as actions will not be executed at the translation time, but static methods used as parameters may be executed.

If you do not see the StaticSupport registry key under HKEY_LOCAL_MACHINE\Software\Microsoft\BusinessRules\3.0, you should add it by performing the following steps.

To add the StaticSupport registry key

1.            Click Start; click Run, type RegEdit, and then click OK.

2.            Expand HKEY_LOCAL_MACHINE, expand Software, expand Microsoft, expand BusinessRules, and then select 3.0.

3.            In the right pane, right-click, point to New, and then click DWORD value.

4.            For Name, type StaticSupport.

If the StaticSupport registry key already exists, and you need to change its value, perform the following steps.

To change the value of the StaticSupport registry key

1.            Click Start, click Run, type RegEdit, and then click OK.

2.            Expand HKEY_LOCAL_MACHINE, expand Software, expand Microsoft, expand BusinessRules, and then expand 3.0.

3.            Double-click the StaticSupport registry key, or right-click it and then click Modify.

One other thing I’ll point out from the screenshots above is the reference to LoanTypeCode.HomeEquityLineOfCredit and the others.  True, I could have checked to see if the value was equal to 113, but this will allow me to update a dll should the values change instead of updating every rule that checked to see if the credit type was open end (this can also be done with a Vocabulary, but then the external functions wouldn’t have access to the values).

Source code, schema, etc for my example can be found here.

Posted on Wednesday, August 8, 2007 8:35 PM | Back to top


Comments on this post: External Functions and the BRE

# re: External Functions and the BRE
Requesting Gravatar...
i am using App.config file in my helper class , but when i test the Policy it showing an exception "Object Reference not set to an instance of Object".
Please Guide me .
Left by Atul Pandey on Jul 01, 2014 6:48 PM

Your comment:
 (will show your gravatar)


Copyright © Evan Koch | Powered by: GeeksWithBlogs.net