Create Templates for Business Rules

You can create business rule and validation templates to help users when they create new business rules. By providing templates, a user can create a rule from a template and modify it as needed, instead of starting with an empty rule.

A template can provide examples of how to configure business and validation rules, for example, how to specify rule conditions, how to write advanced expressions, or examples of how to override properties. Templates themselves are not evaluated.

Templates are defined in the Layout. If you create a new Layout in your extension, you can define business rule templates in the Layout (in metada-rules.json) using the business rules editor. You cannot define business rule templates if you're extending a Layout in a dependency.

Let's say you add a new service connection, and then add a dynamic form that is bound to a business object in that service. A new Layout is created representing the business object. If you plan to use business rules with the component, you can define a business rule template that defines a condition and some property overrides, for example, hiding some fields when the user is in the UK. Anyone extending the Layout can then choose to use the template when creating their own business rules. After creating a rule from the template, they could then edit the rule, for example, so that the fields are hidden for users in Canada instead of the UK.

  1. In the Layout, open the Business Rules tab.
    If you want to create a validation rule, open the Validations tab in the Layout.
  2. Open the Templates tab in the rules editor.
    The editor contains a Templates tab where you can create, view and edit templates. If you don't see the Templates tab, you can't create templates.

    The Templates tab is available if you're working in a "base" dynamic layout, in other words, a Layout which you've created. The Templates tab is not available if you're extending a Layout in a dependency.

  3. In the Templates tab, click Create Rule to open the dialog box for creating a template.

    For example, when creating a business rule template, click the Create Rule next to Form Rule Templates or Collection Rule Templates to open the Create Rule Template dialog box:



  4. Select the Rule Type.
    Select Regular to create a standard business rule. The other rule types (If/else and Switch) are special types of nested rules. For more about these nested rules, see Add an If/Else Rule and Add a Switch Rule.
  5. Enter a label, id, and description for the rule.
    The id is generated automatically based on the label you enter, but you can modify the id if you wish. The description field is not required, but it can be helpful when you later try to understand what a rule is doing, especially when there are many rules.
  6. Click Create.

    The template is added to the list of templates.

  7. Create the template conditions, and define the template.

    In a business rule template you can define examples of business rule conditions and property overrides.

    In a validation template you can define examples of messages, usually error messages or warnings, that should be displayed in the page when the conditions are met.

When a user creates a business rule, if the Layout defines a business rule or validation template, the dialog box for creating the rule contains a Template dropdown list. The user can choose to create an empty rule, or a rule based on the template, and then modify the rule as needed.