Processing events immediately by using when occurs

The when <event> occurs clause instructs the agent to consider the rule for eligibility only when the event received is the event that is specified in the when <event> occurs clause.

A rule that starts with a when <event> occurs clause has the following characteristics:
  • The rule processes a single event in the when <event> occurs clause. When an event is received, the rule is instantiated for this event. The rule instances are only applicable when this event is processed and is no longer applicable when later events arrive.
  • The rule can contain a condition that tests the attributes or relationship of the event, and the attributes or relationships of the bound entity.
  • The rule can contain a reference to now, for example to identify events that arrive out-of-order, see Detecting out-of-order events.
    Warning: If you use expressions that refer explicitly or implicitly to now, such as the last period of or the current month, be aware that now might not refer to the time stamp of the event in the when <event> occurs clause. For more information, see Event processing in agents.

    If a rule with a when <event> occurs clause contains scheduling, the rule cannot be executed. For more information about rule scheduling, see Scheduling the execution of a rule.

Events are processed in the order that they are received by the agent. This order might not be the order in which they were originally generated, as indicated by the time stamps.

In the following example, when a late departure event is received, the state of the bound entity the flight is updated.

when a flight late departure event occurs, called 'the event'
then
	set the state of 'the flight' to Delayed;

The following rule processes an event of type bag not loaded event. The entity that is related to the event is named the flight. When the agent receives a bag not loaded event, the rule prints a message with the arrival gate of the flight.

when a bag not loaded event occurs 
then
	print "Bag not loaded for arrival airport of flight: " + the arrival gate of 'the flight';

The following rule is applied only if a purchase event happens on a Saturday, and when the purchase is received by the agent.

when a purchase event occurs
if
    this purchase event is on Saturday
then
    print "Saturday purchase";