Prevent DataPortal_Create from running expensive business rules

Prevent DataPortal_Create from running expensive business rules

Old forum URL:

mswanson25 posted on Thursday, October 17, 2013

Hi, I have BO which has a bunch of business rules, a couple which are relatively expensive rules which contact the database to insure that some properties are correctly set when saved/updated.

I noticed that these rules run on DataPortal_Create(), and these rules will always fail when the object is initialized, so i don't see the point of running rules just when creating a object for the first time.

I've read discussions on this forum that suggests not using a constructor because of a number of reason, but if I have to choose between initializing default values in two places vs. making expensive database calls on simple object creation....

Is there a way to not get business rules to run on DP_Create, or at least prevent the expensive rules from running?


Thank you!

cfarren replied on Thursday, October 17, 2013

Are there some properties you can check at the start of the rule to determine whether it should be called or not? e.g if the target is new don't call that rule until propertyA or PropertyB are set?

JonnyBee replied on Friday, October 18, 2013

There is a couple of useful techniques to understand:

  1. Use <rule>.Priority to define the sequence of rule execution and RuleEngine will not enter next step if a rule is broken when severity is Error.
    Say f.ex that you have a Required field and when it has a value you must perform some checks. Add the Required rule with Priority=0 (default) and the database check rule with Priority = 1. The effect is that when Required rule is broken the rule engine will no longer run rules with higher priority.
    This technique is very useful for both server and client side execution.
  2. Set a flag in your Rule to tell the rule engine to NOT run this rule in the DataAccess layer.
    in the constructor of your rule set CanRunOnServer = false to prevent the rule from running in any of the DataPortal_XYZ methods.

Copyright (c) Marimer LLC