define (variable) as (variable value)

The define construct creates a variable that you can use to perform actions on entities or events.

Purpose

You use this construct in the action part of a rule to create a temporary local variable.

Syntax

define <variable> as <variable value>

Description

The define <variable> keyword defines the name of the new variable. You cannot use this construct to set a value for an existing variable. The as <variable value> keyword defines the object that the variable refers to. The variable stores the object locally. You can then use this new variable in the rule action. For example, you can perform some actions on a new entity or event that you just defined.

Example

In the following example, you define a new variable called 'the new order' that refers to a new order entity. This new order entity is created from the shipping address and the billing address that are contained in the event. Each item of the order entity is populated with the items from the order event.

when an order event occurs 
then define 'the new order' as a new order where 
	the shipping address is the shipping address of this order event,
	the billing address is the billing address of this order event;
	for each item in the items of this order event:
          - add this item to the items of 'the new order';
    add 'the new order' to the orders of the 'history';