Tutorial: Rule actions
As soon as a rule contains one condition, you can add actions to that rule. Actions define what happens when a rule is fired. There are two kinds of rules:
Find action
Find actions can be used to find elements that are not available in the when part of a rule, but are required in the then part. Most find actions are generated automatically, but there is one kind of find action you can explicitly make:
Create action
With create actions you can create new instances and make new relationships between them. When a rule fires because its conditions are met, then these actions create new data. These newly created data in their turn may trigger other rules to be fired.
Caution: Be aware of the (not always explicitly visible) action and reaction relationships between rules. Especially cyclic relationships between rules (where rule A triggers rule B which triggers rule A, etc.) may result in infinite loops.
There are three types of create actions:
Create actions can take all elements, values and operation outcomes as inputs. This includes the following inputs from the three parts of a rule:
Example app: Grocery store
For our example app we want to realize two different rules:
Rule 1: Calculate shopping cart total price
To implement rule 1, we need to implement the following assign value action:
Rule 2: Calculate volume discount
For rule 2 we first need to create a new price via a create new element action:
Then, we need to assign the new price to the shopping cart by writing the assign descriptor action:
And finally we need to assign the outcome of the operation that calculates a 10% reduction to the reduced price of the shopping cart by writing the following assign value action: