How business rules work

Learn the basics for writing business rules using a near-natural language based syntax.

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 definitions part to define variables for the rule.

The definitions part is optional.

Conditions (if)
Use the if part to specify the conditions for performing the actions in the then and else parts. In the example, the condition is the value of cart is more than 200.

The if part is optional. Rules without conditions perform their actions under all circumstances.

Action part

Actions (then)
Use the then part to define one or more actions to perform if the if part is true. The action in the example says to set decision to "15% discount" if the if part is true.

The then part is mandatory but the then keyword is optional if there is no condition in the rule. The rule must have at least one action.

Alternative actions (else)
Use the else part to define one or more actions to perform if the if part is false. The else part of the example says to set decision to "5% discount" if the if part is false.

The else part is optional. If the if part of a rule is false, and there is no else part, 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.

For example, consider the following rule where a person works from home and the address of this person is an input from a parent node:
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.

One line comments and inline comments both use double dashes (--). The comment finishes at the end of the line. For example:
if 
	the value of cart is more than 200 -- This is a comment 
then 
-- This is a comment
	set discount to 15;