Create a Rule ​
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:
| Input | Rule | Output |
|---|---|---|
| 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, ananyinput can contain any type of input.number
This type includes negative values and numbers with decimals.boolean
This type expects the valuestrueorfalse.string
This type can contain any text, including numbers.date
This type expects a date inmm/dd/yyyyformat.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.
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.
Create a ruleset named
MaxLoan.Create an input named
AnnualIncomewith Type =numberand Label =The annual income.Create a constant named
LoanPercentagewith Type =simpleand Value =25.Click the + sign behind Rules from the left menu.
↳ The Rule details page opens.In the Name field, enter the name for the rule. For example,
LoanCalculation.In the Output name field, enter
MaximumLoanAmount.In the Type list, select number.
In the Expression field, enter the following code to calculate the maximum loan amount:
javascriptAnnualIncome * (LoanPercentage / 100)Click Save.
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:
Move back to the rule again.
Change the code for the Expression to:
javascriptAnnualIncome * 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:
- Click
above the expression.
↳ Rulecube reverts your changes and shows your original code again. - Press
Ctrl+Sto save your work.
Additional resources ​
- How-to Guide: Try Out a Rule.
- How-to Guide: Call a Rule from Your Software.