Custom rule does not fire on change

Discussions related to writing and managing custom business rules.

Moderator: Phil Barton

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

Custom rule does not fire on change

Post by ckootg »

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 »

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: 122
Joined: Fri Jan 06, 2012 6:10 pm

Re: Custom rule does not fire on change

Post by ckootg »

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: 122
Joined: Fri Jan 06, 2012 6:10 pm

Re: Custom rule does not fire on change

Post by ckootg »

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 »

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 »

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: 122
Joined: Fri Jan 06, 2012 6:10 pm

Re: Custom rule does not fire on change

Post by ckootg »

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