Page 1 of 1

Custom rule does not fire on change

Posted: Wed Mar 14, 2012 10:57 pm
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?!

Re: Custom rule does not fire on change

Posted: Thu Mar 15, 2012 12:49 pm
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.

Re: Custom rule does not fire on change

Posted: Thu Mar 15, 2012 8:45 pm
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.

Re: Custom rule does not fire on change

Posted: Tue Mar 20, 2012 3:22 pm
by ckootg
Has anybody else working with custom business rules run into these problems?

Randy, were you able to confirm or disprove this?

Re: Custom rule does not fire on change

Posted: Tue Mar 27, 2012 9:09 am
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;
}

Re: Custom rule does not fire on change

Posted: Tue Mar 27, 2012 11:03 am
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"?

Re: Custom rule does not fire on change

Posted: Thu Mar 29, 2012 5:14 pm
by ckootg
Melissa, Randy - Thanks for the tidbits. Probably not ideal for our validations, but will try to work with what we've got.