Online Helps > Rule Team Server Online Help > Understanding Your Rules > Definitions

The definitions part of a rule gives you finer control over your business rules by letting you set variables at the beginning of your rule.

Variables let you identify and subsequently reference an occurrence of a business term by a convenient name. Using variables can make your business rules less ambiguous as well as easier to understand. A variable that you define is only valid in the rule in which it is defined.

You define a variable by giving it a name of your choice and then setting this variable to a value. This value can be a number (or an arithmetic expression whose result is a number), text, or a predefined business term that already appears in your rule (for example, customer). Once you have set a variable, it becomes available in all the parts of the current rule.

Note
Definitions are presented first, but require an understanding of Conditions and Actions.

The simplest use of definitions is defining a constant value that you can use throughout your rule. For example, by declaring a variable that you call minimum_score in the following rule, you make the rule easier to understand:

definitions
   set `minimum_score' to 200
if
   the credit score of `the borrower' is less than `minimum_score'
then
   in `the loan report', refuse the loan with the message "Credit score below" + "minimum_score"

The Rule Editor defines one variable for each type of business term that it encounters, and identifies it with the word "the". For example, if borrower is something you work with in your rules, the Rule Editor will define a variable called the borrower, available in your drop-down lists.

If your rule requires you to refer to more than one occurrence of a borrower, you have to explicitly define the others in the definitions part, for example:

definitions
   set co-applicant to a borrower
   set loyal customer to a borrower
if
   all of the following conditions are true:
      applicant is married to loyal customer
      loyal customer is insured
then
   upgrade applicant's rating

You can also use where in the definitions part to apply further restrictions on the variables that you declare. For example, you could restrict the variable so that a condition only applies to high income spouses, as follows:

definitions 
   set `high income spouse' to the spouse of `the borrower' 
      where the yearly income of the spouse of the borrower is at least 1.5 * the yearly income of `the borrower'
if
   the age of the latest bankruptcy of `high income spouse' is at least 5
then
   add 60 to the corporate score in `the loan report'

Use Definitions with the Else Part

If a rule contains both definitions and a condition part, the else part of a rule will only be executed if the conditions set in the variables are satisfied and the condition part of the rule is not satisfied.

For example, in the following rule a discount is always applied since any customer will receive at least a 5% discount:

if
   all of the following conditions are true:
      the value of the customer's shopping cart is more than $100
      the category of the customer is Gold
then
   apply a 15% discount
else
   apply a 5% discount

However, if you adjust the rule using the definitions part, a discount is only applied for customers in the Gold category:

definitions
   set applicant to a customer
      where the category of this customer is Gold
if
   the value of the applicant's shopping cart is more than $100
then
   apply a 15% discount
else
   apply a 5% discount

Retrieving all Occurrences of a Business Term

A variable can be used to retrieve a list of all occurrences of a business term. This is done with the ... all instances of construct.

This example creates 3 variables:

definitions 
   set Gold customers to all instances of Customer
      where the category of this Customer is Gold
   set junior Gold customer to a Customer in Gold customers
      where the age of this Customer is at most 15
   set senior Gold customer to a Customer in Gold customers
      where the age of this Customer is at least 65

Related Sections

Using the Rule Editor
Conditions
Actions
The Rule Team Server Environment
Rule Team Server Basics
Explore: Manage Your Projects
Compose: Create Project Elements