emit (an event)
The emit <an event> construct defines an event that the agent can emit.
Purpose
The emit construct is available from the action part of the rule. You use this construct to create and send an event.Syntax
emit <an event>
Description
Rule agents can emit events. In a rule, you can write an action that defines and send an event. You create the new event object and its assigned attributes in the action part of the rule. The event must be based on an event type that is defined in the business model. To define the values of the event, you add the where keyword followed by one or more attributes. The attribute statements must be separated by a comma, and the last statement must be followed by a semicolon. For more information, see new (object).
If the event to be emitted has a collection value, the syntax with the where keyword is limited. Use a different syntax, as shown in the second example below.
The new event that the rule agent emits must be different from the event that triggered the rule.
Example
The following rule checks whether the new arrival time is after the initial arrival time of the flight. If this condition is true, the rule sends an event for the rescheduled flight. The event specifies a new arrival time, the arrival airport, and the flight.
when a flight delayed event occurs, called 'the flight was delayed'
if
the new scheduled arrival time of 'the flight was delayed' is after the scheduled arrival time of 'the flight'
then
emit a new flight rescheduled event where
the arrival airport is the arrival airport of 'the flight was delayed',
the new scheduled arrival time is the new scheduled arrival time of 'the flight was delayed',
the flight is 'the flight';
Example
This example shows how to emit an event with a collection value. The following rule checks whether an order event occurs. If this condition is true, the rule emits an event for this order. The rule specifies the date time and the items of the event. The items are a collection.
when an order event occurs
then
define myCreateOrderEvent as a new create order event where
the event datetime is now;
set the items of myCreateOrderEvent to the items of 'the shopping cart';
emit myCreateOrderEvent;