Use Nested Rules

Nested rules help you avoid having to write complicated conditions and can improve rule organization, especially if you have lots of rules.

A nested rule is simply a parent rule with one or more child rules, indicated in the UI by indentation. When you use nested rules, the children of a rule can override the properties set by its parent(s).

In addition to the typical nested rules, there are two special types of nested rules (If/Else and Switch) that behave slightly differently. These special types are described later, but first let's look at typical nested rules.

Here's a simple example of a nested rule:



This example shows two sets of nested rules:

  • Country is USA and Country is Canada are at the same level
  • Full Time Employees is nested beneath Country is USA
  • Hire Date before 2023 and Hire Date after 2023 are both children of Full-time Employees.

The red numbers indicate the order in which these rules are evaluated at runtime. Let’s take a closer look at what that means:

  1. Evaluation begins at the bottom with Country is Canada. If the conditions for this rule are met, the rule’s property overrides are applied. Next:
  2. Country is USA is evaluated.
    • If the rule's conditions are NOT met, the rule doesn't override any properties. In addition, its child rules (Full-time Employees) are never evaluated.
    • If the conditions for Country is USA ARE met, the property overrides defined in the rule are applied, and Full-time Employees is evaluated.
  3. If the conditions for Full-time Employees are NOT met, the rule does not apply any properties, and its children (Hire Date after 2023 and Hire Date before 2023) are never evaluated.
  4. If the conditions for Full-time Employees ARE met, the property overrides defined in the rule are applied, and its children are evaluated.
    • Hire Date after 2023 is evaluated first, because it is lowest, followed by Hire Date before 2023.

Although you could write a more complex set of conditions to achieve the same outcome, nested rules make it much simpler to apply multiple property overrides at runtime.

Add a child rule

You can add a child rule to any of your extension rules:

  1. Click Create Rule next to the rule that you want to be the parent rule.

  2. Type the Label of the child rule. (The ID field is automatically populated based on the Label, but you can type a different ID if you want.) Click Create.
  3. Right-click the child rule, and then use Move up and Move down in the options menu to move the rule into the position you want.

    Remember, child rules that are peers are evaluated from the bottom up, so the order is important.



When you duplicate a rule, the rule's children are also duplicated. In the example above, if you duplicated Full-time Employees, a new rule (Full-time Employees copy) will appear under the parent (Country is USA), along with its child rules Hire Date not set, Hire Date before 2023, and Hire Date after 2023.

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.

Add a Switch Rule

A Switch rule is a special type of nested rule where instead of evaluating a list of rules, a switch parameter (switchOn) is evaluated, and the parameter's value determines which case is applied.

Let's say you want to apply a rule based on the role of the current user, and there are several different cases. For example, when the user's role is Sales Manager, you want the Sales Manager rule applied, when it's Administrator, the Administrator rule is applied, and so on. You can use the Switch nested rule to apply the appropriate rule based on the value of the user roles field, instead of evaluating a long list of rules at runtime.

Let's create a Switch rule that evaluates the role of a logged in user. You then create some different cases, for example, one case if the user role is Sales Manager, and another case if the role is Administrator. At runtime, the user role is evaluated, and based on the user role value, the appropriate case is applied.

  1. In the Business Rules tab, click Create Rule to open the Create Business Rule dialog box.
    You can create Switch rules for form and collection rules.
  2. Select Switch in the dialog box.
  3. Enter a label, id, and description for the rule. Click Create.
  4. Select the Switch parameter.
    1. Select the Switch parent rule
    2. In the rule's Parameter panel, click Change Parameter, and then select a parameter in the dropdown list. Click Change.

    The Parameter panel displays the parameter (the [] User / Roles field in this example).



  5. Create cases.

    Let's create a case that is applied when the user role is Sales Manager.

    1. Click Create Case next to Switch to open the Create Switch Case dialog box.
    2. Enter a label, id, and description for the case. Click Create.
    3. Select the case, and then enter a parameter value in the Switch Case text field.

      You can enter multiple parameters in the Switch Case field. For this case, enter Sales Manager, so that the case is applied when the user role is Sales Manager.



    4. Set the overrides you want the case to apply.
  6. Create any additional cases.

    For example, create a case called Administrator, and then set the case's parameter value to Administrator. You then set the overrides that should be applied when the user role is Administrator.

  7. Select the last rule in the list of nested rules (the default name is otherwise), and set the property overrides you want the rule to apply.
    The last rule is applied if none of the cases have been applied. You cannot create conditions for the otherwise rule.