Create a Rule

Introduction

This guide explains how to create rules for a ruleset.

Rules are the main engine of rulesets and the logical implementation of a business rule. For example, suppose you implement a business rule for determining the maximum loan amount given a certain income as input. In that case, the rule is the implementation of the business rule that calculates the actual maximum loan amount:

InputRuleOutput

Income

Calculate maximum loan amount

Maximum loan amount

To distinguish rules at the entity and ruleset level, Rulecube speaks of entity rules and global rules. This guide is about global rules.

The result of rules as output

In general, a rule performs a calculation or makes a decision and returns the result as the output of the ruleset. To facilitate different (business) rule scenarios, Rulecube supports different output types, such as string and date. For instance, the aforementioned maximum loan amount output is of the number type.

List of output types and additional rule/output settings

Output types

  • any As its name implies, an any input can contain any type of input.

  • number This type includes negative values and numbers with decimals.

  • boolean This type expects the values true or false.

  • string This type can contain any text, including numbers.

  • date This type expects a date in mm/dd/yyyy format.

  • enum For this type, you can set a list of possible values. For example, good, bad, ok.

  • array This type contains a one-dimensional array of values.

Additional rule/output settings

  • If you select this type, Rulecube adds the Possible values field to the Rule details page, where you can enter the corresponding values.

  • If you select this type, Rulecube adds the Sub type field to the Rule details page, where you can set the type for the array elements.

Procedure

Let's walk through the steps for creating a rule that calculates the maximum loan amount as 25 percent of a person's annual income.

  1. Create a ruleset named MaxLoan.

  2. Create an input named AnnualIncome with Type = number and Label = The annual income.

  3. Create a constant named LoanPercentage with Type = simple and Value = 25.

  4. Click the + sign behind Rules from the left menu. ↳ The Rule details page opens.

  5. In the Name field, enter the name for the rule. For example, LoanCalculation.

  6. In the Output name field, enter MaximumLoanAmount.

  7. In the Type list, select number.

  8. In the Expression field, enter the following code to calculate the maximum loan amount:

    AnnualIncome * (LoanPercentage / 100)

  9. Click Save.

  10. Try the ruleset out.

Revert changes to an expression

As an extra, let's look at the Revert feature for changes to expressions in Rulecube:

  1. Move back to the rule again.

  2. Change the code for the Expression to:

    AnnualIncome * LoanPercentage / 100

Now, let's assume you are unsatisfied with this change and want the previous code back. You could retype the original code if you remember, but Rulecube enables you to revert the changes much easier:

  1. Press Ctrl+S to save your work.

Additional resources

Last updated