How business rules work
A rule defines the specific actions to take when certain conditions are met. A basic rule uses an
if-then statement to associate a condition (if) with an action
(then). The rule states what action to perform when a condition is true, for
example:
if the credit score is less than 200 then set decision to "Loan rejected: credit score too low.";
You write a rule as a sentence in a natural language. The rule is composed of business terms,
operators, functions, and literal values. In the example, the
credit score is a business term defined in the vocabulary of your data model, is less than is an arithmetic function, and 200
is a literal value.
Business applications call the rules to execute them and provide data values for the business
terms. In the example, the rule must access data for the business term the credit score of the borrower.
To provide a complete statement, a rule can consist of four parts: definitions, if, then, and else.
The following example shows the four parts in a rule that decides on what discount to give to customers based on how much they spent:
definitions set cart to the shopping cart of customer; if the value of cart is more than 200 then set discount to 15; else set discount to 5;
Condition part
- Definitions (
definitions) - Use the
definitionspart to define variables for the rule.The
definitionspart is optional. - Conditions (
if) - Use the
ifpart to specify the conditions for performing the actions in thethenandelseparts. In the example, the condition isthe value of cart is more than 200.The
ifpart is optional. Rules without conditions perform their actions under all circumstances.
Action part
- Actions (
then) - Use the
thenpart to define one or more actions to perform if theifpart is true. The action in the example says toset decision to "15% discount"if theifpart is true.The
thenpart is mandatory but thethenkeyword is optional if there is no condition in the rule. The rule must have at least one action. - Alternative actions (
else) - Use the
elsepart to define one or more actions to perform if theifpart is false. Theelsepart of the example says toset decision to "5% discount"if theifpart is false.The
elsepart is optional. If theifpart of a rule is false, and there is noelsepart, the rule does not execute an action.
Reusing input values
Rules in a decision node can’t modify the input values that come from nodes that the decision depends on. When a rule tries to modify an input value, IBM Decision Composer creates a copy of the data so that the input value is never modified.
set the address of decision to the address of 'the person' ;
IBM Decision Composer detects if a rule modifies the address of the company. As soon as there is one, the system creates a copy of the address of the person, so that this address remains unchanged.
Adding comments in rules
You can add comments to help you structure and document your rules.
if the value of cart is more than 200 -- This is a comment then -- This is a comment set discount to 15;