ILOG Rules for .NET User Guides > Rule Studio > Writing 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.

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

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. However, once you have set a variable, it becomes available in all the parts of the current rule.

You define a variable by giving it a name 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). Classes considered as a value type (also known as simple types: number, date, string, Boolean, and so on) cannot be used in statements that deal with the working memory such as "there is at least". This constraint only affects boot types, it does not affect user classes that support literal values.

Implicit variables are variables defined at the BOM level. So, if you have a customer class in your BOM, a variable will be created for it. An implicit variable is defined for each business term, and identified with the article "the". For example, if customer is a business term, a corresponding variable called the customer is available in the Intellirule Editor.

For more information see Implicit Variables.

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

If your rule requires you to refer to more than one occurrence of a business term, you have to explicitly define the other variables in the definitions part.

The following example shows how you can give meaningful names to predefined business terms:

 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 a senior gold customer variable, initialized to a customer who is a gold member and at least 60 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 60;

In This Section

Using Definitions with the Else Part
Describes when an else part of a rule will be executed.
Retrieving all Occurrences of a Business Term
Describes how to use the all <...> construct.