| ILOG Rules for .NET User Guides > ILOG Rule Solutions for Office > Writing and editing rules > Write rule conditions > Test for existence |
Test for existence |
PREVIOUS NEXT |
Several constructs are available that enable you to check whether or not one or more objects of a certain type exist in a given set of data.
Use the there are construct to test whether there are a specific number of objects of a certain type. For example, the following rule check to see if there are exactly two customers:
If there are 2 customers Then...
You can combine this test with an optional where construct to specify one or more additional conditions to apply to any objects found. For example, the following rule condition is only true if there are 10 customers and if each of these 10 customers is a member of the Gold category:
If
there are 10 customers
where the category of each customer is Gold,
Then...
Use the there are at least construct and the there are at most construct to check whether there are more than or less than a given number of occurrences of a particular object:
The following example shows how to check that there are no more than 3 Gold customers:
If
there are at most 3 customers
where the category of each customer is Gold,
Then...
The following more advanced example shows how to check whether there are more Gold customers than Silver customers. This is done by first initializing the following variables:
These variables can then be used in the condition statement to compare the number of Gold customers with the number of Silver customers:
Definitions
set 'silver customers' to all customers
where the category of each customer is Silver;
set 'silver count' to the number of 'silver customers'
If
there are at least 'silver count' + 1 customers
where the category of each customer is Gold,
Then...
To simply test for the existence of a given object (that is, check that there are one or more objects of that type in the data set), use the there is at least one construct.
The following example shows how to check that at least one Customer object exists:
If
there is at least one customer
Then...
The following more advanced example shows how to test if there is at least one senior Gold customer:
Definitions
set 'gold customers' to all customers
where the category of each customer is Gold;
If
there is at least one customer in 'gold customers'
where the age of this customer is at least 65,
Then...
there are at least <number> <objects>
there are at most <number> <objects>
there are less than <number> <objects>
there are more than <number> <objects>
there is at least one <object>
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |