Add an If/Else Rule

An If/Else rule is a special type of nested rule where only the first child rule meeting the conditions is applied, and none of the remaining child rules are evaluated.

You use an If/Else nested rule when only one of the rules in a list of rules needs to be applied. Unlike regular business rules, where every rule is evaluated, the child rules in an If/Else rule are evaluated in order until one is applied; the unevaluated child rules are skipped. This means that rules won't be evaluated if they don't need to be.

For example, you might have a rule that should be applied when the user's role is Sales Manager, and some rules that should only be applied when the user is a sales manager in the UK, or in Canada. Handling this type of situation, where only one rule should be applied, is very simple if you use nested If/Else rules. Let's take a look at how you could do this.

  1. In the business rules editor, click Create Rule to open the Create Business Rule dialog box.
    You can create If/Else rules for form and collection rules.
  2. Select If/Else in the dialog box.
  3. Enter a label, id, and description for the rule. Click Create.

    An If/Else rule containing two child rules is created by default. The default names for the two child rules are "New Rule" and "otherwise", but you can rename them to something more meaningful. You can add as many child rules as you want, but remember that only one of them will be applied.



  4. Select New Rule.

    The first child rule is the first "If" part of the "If/Else" nested rule. In If/Else nested rules, rules are evaluated from the top to the bottom. New Rule is the first rule in the list, so it's the first to be evaluated.

    1. Click Edit, and then define the rule's conditions, and give the rule a meaningful name.

      Let's define this rule so that it's applied to users in the UK with the role Sales Manager.

    2. Set the property overrides you want applied when the conditions are met.
  5. Select the otherwise rule.

    The otherwise child rule is the "Else" part of "If/Else", and is only evaluated if none of the preceding rules were applied.

    1. Click Edit, and then define the rule's conditions, if you wish, and give the rule a meaningful name.

      If you don't set any conditions, the rule is always applied if it's evaluated. If a rule has no conditions you should make sure it's the last rule in the list.

      Let's define this rule so that it's applied to all users with the role Sales Manager.

    2. Set the property overrides you want the rule to apply.
  6. Add and configure additional child rules.

    You can add as many child rules as you want, and arrange the order they are listed.

    Let's add a child rule that is applied to users in Canada with the role Sales Manager, and move the rule below the Sales Managers in UK rule.



    Click Edit to define the conditions, and then set the property overrides you want the rule to apply.

At runtime, starting with the first rule, the rules are evaluated in order until a rule is applied. In this set of nested rules, the last rule is applied only if the user's role is Sales Manager and they are not in the UK or Canada.