Custom rule does not fire on change

Discussions related to writing and managing custom business rules.

Moderator: Phil Barton

Post Reply
ckootg
Posts: 116
Joined: Fri Jan 06, 2012 6:10 pm

Custom rule does not fire on change

Post by ckootg » Wed Mar 14, 2012 10:57 pm

Does custom business rules fire only on the first save since the order was opened, regardless of input parameter changes?

Here's my test set up:

CoreBusinessRules.xml

Code: Select all

<Instance>
    <Name>MyValidationTest</Name>
    <BusinessRule>ValidationTest</BusinessRule>
    <BusinessObjectContext>Order</BusinessObjectContext>
    <Persist>False</Persist>
    <HideFromUser>False</HideFromUser>
    <SaveValidationInstance />
    <ExcludeIfTemplate />
    <InputList>
      <Input>
        <Order>0</Order>
        <Source>IsRush</Source>
      </Input>
    </InputList>
</Instance>
Custom business rule module

Code: Select all

internal class ValidationTest : SoftPro.BusinessRules.Base.BusinessRuleBase
{
    public ValidationError ExecuteImpl(InputParameterHandle<bool> isRushOrder)
    {
        return null;
    }
}
Test routine:
I set a breakpoint set on ExecuteImpl(). I open an order, check the "Rush order" field on the Express Order Entry screen and save. My custom rule is called. Great! Order is still open, I uncheck the "Rush order" field and save again. Custom rule is not called. Why?!

Randy Mellow

Re: Custom rule does not fire on change

Post by Randy Mellow » Thu Mar 15, 2012 12:49 pm

Since the rule is a save validation it should fire on each save regardless of parameter changes. I'll need to experiment with this and see if I can reproduce that behavior.

ckootg
Posts: 116
Joined: Fri Jan 06, 2012 6:10 pm

Re: Custom rule does not fire on change

Post by ckootg » Thu Mar 15, 2012 8:45 pm

Another thing I noticed is that for field validations on text fields, the validation is not triggered when the text field is blanked out.

ckootg
Posts: 116
Joined: Fri Jan 06, 2012 6:10 pm

Re: Custom rule does not fire on change

Post by ckootg » Tue Mar 20, 2012 3:22 pm

Has anybody else working with custom business rules run into these problems?

Randy, were you able to confirm or disprove this?

Melissa McBerkowitz
Posts: 91
Joined: Wed Sep 10, 2008 3:33 pm
Location: Raleigh, NC
Contact:

Re: Custom rule does not fire on change

Post by Melissa McBerkowitz » Tue Mar 27, 2012 9:09 am

After the first time they are called, business rules only run again if one of their dependencies change. Every input is not necessarily a dependency. An input is only considered a dependency if it's value is checked during the rule's execution. Since your rule simply returns null, it takes no dependencies on inputs and would never refire. In comparison, this code would check your input's value and cause the rule to refire when isRushOrder changes:

if (isRushOrder.Value)
{
return null;
}
else
{
return null;
}
Melissa McBerkowitz
VP of Product Strategy, SoftPro

Randy Mellow

Re: Custom rule does not fire on change

Post by Randy Mellow » Tue Mar 27, 2012 11:03 am

I apologize for not getting back to you sooner. Field validations do not fire when the field value is reset using F2. Is this what you mean when you say "the text field is blanked out"?

ckootg
Posts: 116
Joined: Fri Jan 06, 2012 6:10 pm

Re: Custom rule does not fire on change

Post by ckootg » Thu Mar 29, 2012 5:14 pm

Melissa, Randy - Thanks for the tidbits. Probably not ideal for our validations, but will try to work with what we've got.

Post Reply