Describe use cases and limitations of business rules
Business rules enable developers to implement logic on data stored in Common Data Service. Because the rules apply to the data, and not to a specific app, they take effect however the data is used. For example, if the value of the Country field in an entity is entered as Canada, a business rule can enable a six-digit alphanumeric Postal Code field and hide the five-digit numeric Zip Code field used for U.S. addresses.
Business rules consist of conditions and actions. Conditions are circumstances that must be met for the rule to apply, and actions are the procedures taken when the circumstances of the condition are met. When a developer selects an entity in the Power Apps portal, selects the Business Rules tab, and clicks Add business rule, a New business rule canvas appears, as shown in Figure 2-13.
FIGURE 2-13 A New business rule canvas in the Power Apps portal
As with a business process flow, developers can drag elements from the Components pane to the canvas. Selecting an element on the canvas causes the Properties interface for that element to appear in the right pane. The combination of conditions and actions creates an IF/THEN logic statement that appears in the Business Rule (Text View) box on the canvas.
For a condition, the developer configures one or more rules specifying when the actions should occur. In the figure, the condition calls for the Country field to have the value Canada. When that condition is met, the specified actions occur. The developer can then create actions that cause the U.S. Zip Code field to be hidden and the Canadian-format Postal Code field to be shown.
Conditions can be more complex, with multiple rules that use Boolean and/or operators to specify whether both conditions must be met for the actions to apply or either one of the conditions. The rule can also include multiple actions that execute when the condition is met.
The most common functions of business rules are to simplify the process of supplying data for users and verify the accuracy of the data that users supply. To that end, developers can create rules that set values for fields, clear the values from fields, and validate the data entered into fields. In model-driven apps (only), business rules can also show, hide, enable, and disable fields. For example, when users are required to supply their annual income in a field, a rule can enable additional fields for verification if the income exceeds a specified amount.