Defining expressions in Declare Expression rules
Define how your application calculates target properties by building expressions. When you build expressions, you create relations between properties so that an application can automatically update property values at run time. As a result, you increase the level of automation and flexibly respond to changing circumstances.
For example, you can create a Declare Expression rule that automatically calculates shipping costs based on the total weight of all items that a customer orders in an online shop. When the customer adds items to the order and the total weight changes, a Declare Expression rule automatically updates the shipping costs.- In the navigation pane of Dev Studio, click Records.
- Expand the Decision category, and then click Declare Expression.
- In the list of instances of declare expressions, open the instance that you want to edit.
- Optional: To provide additional information about the rule, on the
Expressions tab, in the Overview section,
enter a brief description:
- In the Description field, briefly explain the purpose of the
rule.
For example: Enter This declare expression calculates the tax value that is 6% of the total price of all items in the shopping cart in an online shopping application. - In the Usage field, briefly explain the scenarios and
elements of your application where the declare expression applies.
For example: Enter This declare expression calculates the tax value in the checkout page of a shopping application.
Tip: Providing additional information about a declare expression is very useful to quickly share details of the rule with other developers. - In the Description field, briefly explain the purpose of the
rule.
- In the Build Expressions section, click Add condition.
- In the IF field, enter or select a property to evaluate at run
time.The list includes properties from the Apply To class that you selected during rule creation. For more information, see Creating Declare Expression rules.
- In the list of comparators, select a comparator to apply during property evaluation.
- In the text field, provide a property to evaluate against the property from the IF field.
- Optional: To define more conditions, click Add a row, add a condition
before or after the current condition, and then repeat steps 6 through 8.
Result: By default, the system groups conditions by using the AND comparator. At run time, your application applies the result after all the conditions with the AND comparator evaluate to true. - Optional: If you have multiple rows, to apply the result of the expression when any of the rows
evaluates to true, click AND, and then click
OR.
For example: When the rows include price values of different items that a customer can add to an online shopping cart, and you select an OR comparator, the application applies the result of the expression when the customer adds any of the products to the shopping cart. - In the Then set row for your target property, define how the
declare expression determines the target property:
- To determine the target property as a result of a string, in the list, select Value of, and then, in the text field, enter the string that calculates the property.
- To determine the target property as a result of a decision tree, in the list, select Result of Decision Tree, and then, in the text field, enter a decision tree to compute at run time.
- To determine the target property as a result of a decision table, in the list, select Result of Decision Table, and then, in the text field, enter a decision table to compute at run time.
- To determine the target property as a result of a map value, in the list, select Result of Map Value, and then, in the text field, enter a map value to evaluate at run time.
- Optional: To add more conditions to the expression, click Add condition,
and then repeat steps 6 through 11.
Note: If you create multiple conditions, at run time, processing stops after your application determines the first expression that evaluates to true. - In the Set row for the target property, provide that you want the
system to apply if all the conditions evaluate to false:
- To determine the target property as a result of a string, in the list, select Value of, and then, in the text field, enter the string that calculates the property.
- To determine the target property as a result of a decision tree, in the list, select Result of Decision Tree, and then, in the text field, enter a decision tree to compute at run time.
- To determine the target property as a result of a decision table, in the list, select Result of Decision Table, and then, in the text field, enter a decision table to compute at run time.
- To determine the target property as a result of a map value, in the list, select Result of Map Value, and then, in the text field, enter a map value to evaluate at run time.
- Click Save.

Previous topic Creating Declare Expression rules Next topic Specifying pages and classes for a declare expression