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.