new (object)

The new <object> construct creates a new instance of the specified object type.

Purpose

The new construct is available from the action part of the rule. You use this construct to create a new object, for example a new event or a new entity.

Syntax

new <object> where

Description

The new <object> construct instantiates an object. The new object is based on a type that is defined in the business object model. To define the values of this new object, 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.

By default, the attributes are mandatory unless you specified a default value. You can modify the business model to make some attributes optional. For more information, see Mandatory and default values.

Examples

In the following example, the rule checks for the existence of an order entity upon arrival of a pizza order event. The rule creates the order entity if it does not exist.

when a pizza order occurs
if
  ‘the order’ is null
then set ‘the order’ to a new order where
  the customer is the customer of this pizza order,
  the start time is this pizza order,
  the order status is PLACED,
  the pizza store is the pizza store of this pizza order;
  set the pizzas of ‘the order’ to the pizzas of this pizza order;

In the following example, if a customer event is triggered, the rule creates a coupon object for the customer and emits a new coupon sent externalevent.

when a customer event occurs, called 'the event'
then
	add a new coupon where 
			the amount is 100, 
			the long description is the description of 'the event',
			the short description is "New special offer coupon." 
		to the coupons of 'the customer';    
	add 'the event' to the customer events of 'the customer';
	emit a new coupon sent external where 
		the customer is 'the customer';