ILOG Rules for .NET User Guides > ILOG Rule Team Server for SharePoint > Structure of Business 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 something 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 even an arithmetic expression), 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.

To define a constant

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 upgrade value in the following rule, you make the rule easier to understand:

 Definitions
     set upgrade value to 250
 If
     the value of the customer's shopping cart is more than upgrade value
 Then
     upgrade the customer's status
To identify other occurrences of a business term

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 customer is something you work with in your rules, the Rule Editor will define a variable called the customer, available in your drop-down lists.

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

 Definitions
     set applicant to a customer
     set loyal customer to a customer
 If
     all of the following conditions are true:
         applicant is married to loyal customer
         loyal customer is insured
 Then
     upgrade applicant's rating
To further restrict a variable

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 it can only be set to valued customers as follows:

 Definitions
     set loyal customer to a customer
         where the category of this customer is Gold
 If
     the value of the shopping cart of loyal customer is more than $200
 Then
     Apply the super discount

Another example shows how to declare the a senior Gold customer variable, initialized to a customer who is a Gold member and at least 65 years old.

 Definitions 
   set a senior Gold customer to a Customer
       where all the following conditions are true:
           the category of this Customer is Gold
           the age of this Customer is at least 65

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: