6.5. Rule Templates

6.5.1. The Guided Rule Template

Rule Templates allow the user to define a rule structure. They provide a place-holder for values and data, and they populate templates to generate many rules. From the user’s perspective, Guided Rule Templates are a parametrized guided rule with a data table which provides parameter values. This can allow for more flexible decision tables and it can enhance the flexibility of rules in existing databases. For information on managing dependencies of Rule Templates, see the Dependency Management for Guided Decision Tables, Scorecards, and Rule Templates section of the Red Hat JBoss BRMS Development Guide.

Procedure: Creating a new Guided Rule Template

  1. In the Project Explorer view, do one of the following:

    1. If you are in the Project view, select the organizational unit, repository, and the project where you want to create the template.
    2. If you are in the Repository view, navigate to src/main/resources/ and the SUBFOLDER/PACKAGE where you want to create the project folder for the rule template.
  2. In the perspective menu, go to New ItemGuided Rule Template.
  3. In the Create new Guided Rule Template dialog window, specify the rule template name:

    1. In the Resource Name text box, enter the Guided Rule Template name and click OK.
  4. The new Guided Rule Template is now created and under the selected project.

Figure 6.25. Guided Template Editor

Red Hat JBoss BRMS Guided Template Editor screenshot example for BRMS USer Guide 6.0.2.
Note

Using a plain rule template and manipulating rules and spreadsheets directly from Business Central is not supported by Red Hat. It is recommended that you create and use Guided Rule Template using Business Central.

6.5.2. WHEN conditions in the Guided Rule Template

The Guided Template Editor in Business Central allows users to set rule templates where the data is kept separate from the rules.

Note

In the Guided Rule Template example procedures below, a Nurse Rostering data model was created for a fictitious hospital, Sister Veronica’s.

Procedure: Using the Guided Template Editor with WHEN Constraints

  1. Assuming you have already set up a Data Model for your project (as described in Section 5.3, “Creating Data Object (Not Persistable)”), select the plus icon 5686 to the right of the WHEN section of the Guided Template Editor.
  2. A dialog window will appear with available condition templates to choose from. In the example below, we select the Applicant…​ condition from the list.

    Figure 6.26. Nurse Roster WHEN Dialog Window

    5687
  3. Click OK and the Guided Template Editor will display your WHEN condition.
  4. Click on the newly added WHEN condition. In the example below, it is the "There is a Loan" condition. A "Modify constraints for LoanApplication" dialog appears.

    Figure 6.27. Modify Constraints Dialog

    5688
  5. From here you can add a restriction on a field, apply multiple field constraints, add a new formula style expression, apply an expression editor, or set a variable name.
  6. In the example below, we will add a restriction of approvedRate to the condition.

    Figure 6.28. Adding a Restriction on a Field

    5689
  7. Once selected, the dialog window closes automatically.
  8. Next to the newly selected restriction will be a drop down box to choose an operator. In the example below, we have chosen an operator of "less than."

    Figure 6.29. Restriction Drop-Down Menu

    5690
  9. By selecting the Edit Icon 5691 within the restrictions field, you will be able to define the field value with a literal value, template key, a formula, or expression editor.
  10. By clicking on the WHEN condition again, we can supply a variable name to help define the restriction. In the example below, we name it "a" and click Set.

    Figure 6.30. Setting a Variable Name

    Setting the Variable Name for a condition in the Guided Template Editor in BRMS User Guide 6.0.2
  11. Continue to add WHEN conditions as appropriate for the project.

6.5.3. THEN Actions in the Guided Rule Template

The THEN section of a rule holds the actions to be executed when it matches the WHEN section.

Procedure: Using the Guided Template Editor with THEN Actions

  1. Select the plus icon 5686 to the right of the THEN section of the Guided Template Editor to input THEN actions.
  2. A dialog window will appear with available action templates to choose from. In the example below, we select the Modify a…​ action from the list.

    Figure 6.31. Nurse Roster THEN Dialog Window

    5695
  3. Click OK and the Guided Template Editor will display your THEN action.
  4. Click on the newly added THEN action. In the example below, it is the "Modify value of LoanApplication [a]" 5691 action. An Add a field dialog appears.

    Figure 6.32. Add a Field Dialog

    An Add a field dialog for the Guided Template Editor in BRMS User Guide 6.0.2
  5. Within this dialog, you can choose a field from the Add field drop-down menu.
  6. Once selected, the dialog window closes automatically.
  7. By selecting the Edit Icon 5691 within the item field, you will be able to define the field value with a literal value, template key, or a formula.

6.5.4. Data Tables in the Guided Rule Template

Data tables can be altered within the Guided Template Editor directly by clicking on the Data tab. The procedure below illustrates how to alter the data created within Guided Template Editor itself.

Procedure: Using the Guided Template Editor with Data Tables

  1. Click on the Data tab at the bottom of the Guided Template Editor in order to access the newly created data table.
  2. Click the Add row…​ 5697 button to add more table rows.
  3. Input additional data into the table. In the example below, we see the ServiceLessThan, ServiceGreaterThan, EmployeeRating, and VacationTime column options and supply data to each field.

    Figure 6.33. Data Table for Guided Template Editor

    5927
  4. To view the code, click the Source tab at the top of the Guided Template Editor.
  5. Save the template when you are finished working in the Guided Template Editor.