when (event) occurs

This construct enables a rule to listen for a specific event and to react immediately to this event.

Purpose

The construct when <event> occurs listens for the arrival of an event and optionally applies conditions to that event.

Use this construct to write a rule that reacts on a specific event.

Syntax

when <event> occurs [, called <varname>]
  [where <condition>]

Description

The construct when <event> occurs specifies the event to process. This construct tests only one event.

The event that occurs is the event that the agent just received. The rule that acts upon arrival of this event is only valid at the time when the agent receives the event. The rule is not applicable to events that were previously processed by the agent.

An implicit variable is created that you can use in the rest of the rule, for example this bag not loaded event. Optionally you can create a local variable to reference the event, for example 'the event'. To create a local variable, use the construct , called <varname>. If you specify a local variable for the event, the comma before called is required.

To test the event for a specific condition, you can add the where construct followed by a condition.

Example

The following rule is executed when the agent receives a "bag not loaded" event and the entity related to the event is "the fight". If these conditions are true, the rule prints a message with the arrival gate of the flight.
when a bag not loaded event occurs 
if 
	the flight of this bag not loaded event is 'the flight'
then
	print "Bag not loaded for arrival airport of flight: " + the arrival gate of 'the flight';

The following example shows the use of the optional called and where constructs, to specify a local variable for the event, and a condition on the flight referenced in the event.

when a bag not loaded event occurs, called 'the event'
	where the flight of 'the event' is 'the flight'

if 
	the date of 'the event' is after the original departure date of 'the flight' 
then
	print "Bag not loaded for arrival airport of flight: " + the arrival gate of 'the flight';