WHEN statement adds a simple event handler.
WHEN eventClause eventExpr [ORDER [DESC] orderExpr1, ..., orderExprN] DO eventAction;
WHEN statement adds a simple event handler. In a condition expression you can implicitly declare local parameters that can then be used in the event handler.
ORDER block can be used to define the order in which the handler will be called for an object collection for which the condition on the simple event has been met.
WHEN statement is much like the following statement:
ON eventClause FOR eventExpr [ORDER [DESC] orderExpr1, ..., orderExprN] DO eventAction;
but it also has a number of advantages.
Event description block. Describes the base event for the created handler.
An expression whose value is used as a condition for the created simple event. If the obtained property does not contain the
PREVoperator, the platform automatically wraps it into the
A context-dependent operator that describes an action to be added as an event handler.
Keyword. Specifies a reverse iteration order for object collections.
orderExpr1, ..., orderExprM
A list of expressions that defines the order in which handlers will be called for object collections for which an event condition has been met. To determine the order, first the value of the first expression is used; then, if equal, the value of the second is used, etc.
name = DATA STRING (Stock);
balance = DATA INTEGER (Sku, Stock);
// send an email when the balance is less than 0 as a result of applying session changes
WHEN balance(Sku s, Stock st) < 0 DO
EMAIL SUBJECT 'The balance has become negative for the item ' + name(s) + ' in the warehouse ' + name(st);
order = DATA Order (OrderDetail) NONULL DELETE;
discount = DATA NUMERIC[6,2] (OrderDetail);
WHEN LOCAL CHANGED(customer(Order o)) AND name(customer(o)) == 'Best customer' DO
discount(OrderDetail d) <- 50 WHERE order(d) == o;