views:

182

answers:

3

Hello

I'm trying to create what I think should be a relatively simple business rule to operate over repeating elements in an XML schema.

Consider the following XML snippet (this is simplified with namespaces removed, for readability):

<Root>
  <AllAccounts>
    <Account id="1" currentPayment="10.00" arrearsAmount="25.00">
      <AllCustomers>
        <Customer id="20" primary="true" canSelfServe="false" />
        <Customer id="21" primary="false" canSelfServe="false" />
      </AllCustomers>
    </Account>
    <Account id="2" currentPayment="10.00" arrearsAmount="15.00">
      <AllCustomers>
        <Customer id="30" primary="true" canSelfServe="false" />
        <Customer id="31" primary="false" canSelfServe="false" />
      </AllCustomers>
  </AllAccounts>
</Root>

What I want to do is to have two rules:

  • Set /Root/AllAccounts/Account[x]/AllCustomers/Customer[primary='true']/canSelfServe = true IF arrearsAmount < currentPayment
  • Set /Root/AllAccounts/Account[x]/AllCustoemrs/Customer[primary='true']/canSelfServer = false IF arrearsAmount >= currentPayment

Where [x] is 0...number of /Root/AllAccounts/Account records present in the XML.

I've tried two simple rules for this, and each rule seems to fire x * x times, where x is the number of Account records in the XML. I only want each rule to fire once for each Account record.

Any help greatly appreciated!

Thanks

Andrew

A: 

Make sure that the rules have the same Priority, just in case (I had issues with priorities before). I've also saw that at the Rules level, there is a property called maximum Execution Loop Depth, which assigns how many times can a rule be reevaluated. Try to put 1 there, if you're sure that your rules should only be evaluated once per payload. I hope this helps.

Wagner Silveira
A: 

Check your predicate. The rule fires once for each matching combo of fields used in the predicate.

Jennifer Zouak
A: 

This post shows how to effectively unit test BizTalk Business Rules :

http://whiteboardworks.com/2010/03/unit-testing-biztalk-business-rule-engine

I hope that helps. Regards.

Bruno Spinelli