BizTalk BRE Custom Functions

Creating Custom Functions

The other day i was using BusinessRules Composer and i needed to do something simple.  I needed to concatenate two strings.  I looked at the out of the box Functions provided saw an add, threw it in there dragged over my xsd string elements and BOOM!

My object wasn’t numeric so i couldn’t add.  You would think* you could be able to add any primative type, but you can’t.  So what i decided to do was add a .NET class to do it for me.  So i did and i used the static method below to accomplish my goal

public static string concatenate(string a, string b){ return a + b; }

Pretty simple huh ?

So i built my C# class library deployed it to the GAC.

So you would thing i could switch over Business Rules Composer(BRC) and see my newly created assembly.  WRONG.  Everytime you make changes to your library and re install to GAC you have to restart BRC.  Which really stinks.

Anyways, once i restarted i simply dragged my concatinate function into my rule, and then the strings… no errors … time to test.

BRE Static Code Execution

Well i went to test it and nothing happened.. WT*! so after about 30 mins went by trying to debug, write to the event log, or even write to a file i decided it really wasn’t executing my code.  So with some research i found that BRE will not execute Static Code unless

Either assert an instance of the class into the working memory of the BRE or enable invoking static methods without requiring an object instance by setting the value of the following registry key to 1 or 2: HKLM\SOFTWARE\Microsoft\BusinessRules\3.0\StaticSupport (DWORD)

So obviously the easiest is to flip a bit in the registry, BUT you really dont want other people having to muck with the registry to execute your code?   So i investigated what “assert an instance of the class” one. 

I was executing these rules in a BizTalkOrchestration and here is what you have to do to accomplish the assert.  What i found was basically any variable type passed to the .Execute call in the RulesEngine will end up being statically asserted.  Knowing this i created a variable in my orchestration of the .net class type that i want to be asserted.  I then went back and edited my call rules shape and added at the end of my parameter list the variable i just created.


Volia!  It worked and executed my code phew!.  Anywho i just wanted to share those nuggets with you because there is a major lack of documentation about BRE customizations.



Take care.

Tagged with: , , , ,
Posted in BizTalk
3 comments on “BizTalk BRE Custom Functions
  1. Muru says:

    pls explain the variable you added. I am confused

  2. NIck says:

    So if you look at the call rules shape above, you will see a BREForStaticAssert variable. In Visual Studio Orchestration view i added a new Variable of JobApplicationBREFunctions class type. This class was the .net class that contained all of my BRE Static functions.

    Does that help ? Let me know what else you might need.

    • Steve Newton says:

      Hey Nick, may be being a little thick but it looks like it has to be referenced in the project first and then you can add it as a type to your parameter. When I build it, it grumbles about being referenced twice. any ideas?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: