Rule actions
Rule actions define what to do when the if part of the rule is true or
false.
You define actions in the then and else parts of a rule. A rule action consists of at least one
action phrase that the rule executes when the if part of
the rule is true. It can also contain action phrases to execute when the if part of the rule is false.
You define actions in the following parts of a rule:
then: This part defines actions that the rule executes when theifpart of the rule is true or when noifpart exists.else: This optional part defines actions that are executed when theifpart of the rule is false. You do not have to declare anelsepart for a rule.
The then part of a rule must define at least one
action. If the then or else part contains multiple actions, the rule executes the
actions in their listed order.
Example of the then
part
The following rule applies a discount of 15% only when the value of the shopping cart is more than $100, otherwise the rule applies no action.
if the value of the shopping cart is more than $100 then apply a 15% discount on the shopping cart;
Example of the else
part
The following rule applies a change when the conditions are met (then), or a different change when the conditions are not met
(else):
if
'the loan report' is approved
and the loan grade in 'the loan report' is one of { "A", "B", "C" }
then
in 'the loan report', accept the loan with the message "Congratulations! Your loan has been approved";
else
in 'the loan report', refuse the loan with the message "We are sorry. Your loan has not been approved";
Example of an action that calls methods
An action statement can invoke a method on a business term. You perform the method by using an action phrase from the rule vocabulary. The method can be a static method or a member of a class.
The following action statement uses apply to call the
applyDiscountmethod, and display to
call thedisplayMessage method.
then apply a 10% discount; display the message: "You received a discount!";
Rule actions for lists of business terms
You can define actions that a rule executes for each item in a list.
You use the operator for each <item> in <list>
to apply actions to items in a list.
The following group of action statements applies to every item in the list of expensive items.
then for each item in expensive items: - apply 5% discount to this item; - display the message: “A 5% discount has been applied”;