Common rule types

There are many different types of rule. To help you choose and achieve a specific goal, consult the list of common types.

Act when an event occurs

These rules define the actions to take when an event of a certain type happens. The following rule shows a simple example of this rule type.

when a Purchase occurs
then
   print "A purchase order has been sent";

Create an entity when an event occurs

These rules create a bound instance of an entity when an event of a certain type happens. The following example uses the new operator to create an instance of Customer and populate the attributes.
when a Purchase event occurs
if
   'the customer' is null
then
   print "Creating a new entity using key: " + the eventKey of this Purchase event;
   set 'the customer' to a new Customer where
      the key is the eventKey of this Purchase event;
else
   print "The agent is already bound using key: " + the eventKey of this Puchase event;

Delete an entity when an event occurs

These rules delete a bound instance of an entity when an event of a certain type happens. The following example shows how to set a bound variable to null.

when an account closure event occurs
if 'the account' is not null
then
   print "Deleting the entity with key: " + the eventKey;
   set 'the account' to null;

Act if more than one event occurs within a time period

These rules define the actions to take when an event of a certain type happens more than once within a time period. The following example shows a rule that executes when two events of type Purchase event happen within the last 10 seconds.

when a Purchase event occurs
if
   the number of Purchase events during the last period of 10 seconds is more than 1
then
   print "We have already seen a purchase event within the last period!";

The following examples show two slightly different rules that do the same thing when two events of type Purchase event happen within less than a minute.

when a Purchase event occurs
if
   the number of Purchase events after 60 seconds before now is more than 1
then
   print the name of this rule + " Found more than one" ;
when a Purchase event occurs
if
   the number of Purchase events during the last period of 60 seconds is more than 1
then
   print the name of this rule + " Found more than one" ;

Update a bound entity based on the content of an event

These rules update a bound instance of an entity when an event of a certain type happens. In the following example, the entity contains a field that is named the most recent order and the event contains a field that is named the amount. When a Purchase event occurs, the amount is updated by the content of the Purchase event.

when a Purchase event occurs
then
   set the most recent order of 'the customer' to the amount;

Act when an event that contains something of interest occurs

When an event does happen, it is not always necessary to act. In the following example, the rule filters the incoming events and executes only if the product attribute is equal to Car.

when a Purchase event occurs
   where the product is "Car"
then
   print "We've sold a car!";

Delay when an event is processed

You can delay the processing of an event by a set time. In the following example, the rule waits 10 seconds. In other words, the rule is scheduled to execute 10 seconds after the event happens.

when a Purchase event has occurred 10 seconds ago
then
   print "An purchase event happened 10 seconds ago";