Define business rules - Introduction

Completed

Business rules are declarative logic and validation that is associated with a Dataverse table without writing code.

With business rules you could:

  • Set the value in a column.

  • Change a column's requirement level.

  • Validate data and show error messages.

  • Change a column's properties in a model-driven app form.

  • Prompt the user with a recommendation in a model-driven app form.

The logic defined by a business rule can be applied client-side within a model-driven app form and/or server-side when a Dataverse row is created or updated. Client-side means that the rule is applied immediately within the app when a user changes a field. Server-side means when the row is saved and the logic is performed during the transaction before the data is saved into the database.

Because a business rule can operate at the server-side, the conditions and actions in the rule applies to Dataverse data changed by model-driven apps, canvas apps, Power Pages sites, Power Automate cloud flows, or the Dataverse APIs.

To determine where a business rule operates, you must specify its scope.

Scope

The scope on a business rule defines when the logic in the business rule is applied.

Scope Applies to
Entity(Table) All model-driven main forms client-side and data changes server-side. This is the default when creating a new business rule.
All forms All model-driven main forms and the quick create form
Specific form Only that specific model-driven main form

Tip

To use a business rule with a canvas app you should set the scope to Entity.

Business rules and model-driven app forms

Business rules were originally developed to replace simple JavaScript in model-driven app forms. It's a common requirement to manipulate the properties and value columns on the form at runtime based on the values entered, or selected, by the user in other columns.

On model-driven app forms business rules can:

  • Show or hide a column

  • Make the column editable or read-only

  • Change the requirement level for a column

  • Prompt the user with a recommendation

  • Set or clear the value within a column

Important

Business rules can only perform actions on table columns on the form and cannot change the properties of sections or tabs.

These actions are performed when:

  • The form is opened.

  • When the value for a column referenced by the rule is changed.

Note

Business rules are not applied in the form's save event.

Should I use a business rule or client-side scripting with JavaScript?

JavaScript can be used in model-driven app forms to perform many of the actions that business rules can but you can achieve a whole lot more with client-side scripting:

  • JavaScript has full access for manipulating all types of form controls including tabs, sections, and subgrids. Actions in business rules are limited to only table columns.

  • Business rules can only access the columns on the form/table and can't access rows in one-to-many or many-to-one relationships. With client-side scripting you can use the Web API to access rows in those relationships.

  • Business rules are limited in their formulas to simple addition, subtraction, division, or multiplication of two columns.

  • Recommendations are only available in business rules.

Server-side business rules

When the business rule's scope is set to Entity, the rule's conditions are evaluated when the row is saved. The logic is performed during the preoperation stage of the database transaction. A business rule that shows an error message will prevent the save and rollback the database transaction.

Note

Actions that only apply to model-driven apps will be ignored when the rule is run server-side.