Mandatory attributes and relationships

In the business model, you can define the attributes and relationships that are optional or required for the creation of an event or entity instance in a rule.

In a rule action, you can emit a new event or create an instance of an entity. This new event or entity instance must have attributes or relationships that define it. The attributes and relationships are based on the event and entity types that are defined in the business model.

By default, attributes and relationships are optional. However, you can indicate that an attribute or a relationship is required when you create a new event or entity in a rule, by adding a [mandatory] keyword in the definition.

You can also specify a default value. When you add a default value, this value is used when building the object if the attribute is not specified in the rule.

Attention: Multiple relationships cannot be mandatory.

If you want an attribute to be required, you can add the [mandatory] keyword on an attribute or on a simple relationship.

In the following example, the relationship to the departure airport is specified as mandatory.

a flight is related to a departure airport [mandatory].
You can then write the following rule, which creates an instance of a flight entity where the departure airport is a required attribute.
 when a flight airport movement occurs, called 'the event' 
then 
	set 'the flight' to a new flight where 
	the departure airport is the airport of 'the event';

Default values

You can add a default value to an attribute. The default values are applied to the attributes of the entity or event if no value is specified in the rule action. Otherwise, the default values are ignored.

The default types can be text, numeric, or integer.

The following example shows how to add a default value for the description attribute:

a coupon is a concept with a description (text, "Enter a description" by default) and an amount (numeric).

Example

For example, in a business model, the default number of miles for a flight is 1000:

a flight has a mileage (numeric, 1000 by default).

If you write a rule that creates a flight entity without specifying the mileage of the flight, the new flight entity has a default mileage of 1000.

However, if you specify that the mileage of the new flight entity is 2000, the default value is ignored, for example:

then
    set 'the flight' to a new flight where
        the mileage is 2000;