Friday, December 18, 2015

Create and edit business rules

Why business rules?

Business rules provide an easy declarative way to consistently evaluate the business logic on both client and server, without the need to write code. The client-side logic evaluation is more immediate because it is performed when you open and update the record form, while the server-side provides consistent logic evaluation on the server.
  • The business rule is executed only on the client, if the rule’s scope is set at a form level (all forms or a specific form). The rules are executed when a record form is loaded and updated.
  • The business rule is executed both on the server and client, if the rule’s scope is set at an entity level. The rules on the server-side are executed when a record is created or saved.

What can business rules do?

Business rules allow for a subset of the capabilities provided by form scripts. You can define conditions and apply the following actions:
  • Set field values
  • Clear field values
  • Set field requirement levels
  • Show or hide fields
  • Enable or disable fields
  • Validate data and show error messages
Business rules can be set to apply to all Main or Quick Create entity forms or specific Main forms that you choose. You can also set the rule to apply to an entity.
You can transport business rules from one organization to another by including them in a solution and you can install solutions that contain business rules.

Examples of how to set or clear field values

Let’s consider a couple of examples. With the first rule, for any immediate purchase, you apply a 5% discount. With the second rule, you clear all discounts if the purchase timeframe is unknown,
The following rule definition shows how to set a field value to a 5% discount for immediate purchases.
Set field in Opportunity in Dynamics CRM
The following rule definition shows how to clear a field value – clear all discounts, for purchases with an unknown purchase timeframe.
Action to clear field in Dynamics CRM
Clear field in Dynamics CRM

How do I configure business rules?

First, you need to have the privileges necessary to navigate to Settings > Customization. This typically requires the System Administrator or System Customizer security role. To activate a business rule, you must have the Activate Business Rules privilege.
noteNote
Business rules will only work for Updated Entities or custom entities.
There are four ways you can view, create, or edit business rules:
Solution > Entity
From a solution, such as the default solution, you will find a Business Rules node for all entities.
Business Rules on the account entity in CRM
Solution > Entity > Field
When you view an entity field, you will find a Business Rules node that will show you only the business rules that include this attribute.
Business Rules on a field in Dynamics CRM
Form Editor
From the form editor, you can use the Business Rules button in the ribbon to show the Business Rules Explorer on the right side. This will show you all business rules that will be applied just for this form.
If you create a rule from the form editor, the default scope is for that form. More information: Set the scope
Business Rules for the Form in Dynamics CRM
Form Editor > Field
When you view the properties for a field that is used in a form, you will see a Business Rules tab that shows you the business rules that include this attribute.
Business Rules on Form Field in Dynamics CRM
If an existing rule is similar to a rule you want to make, you can open that rule and use the Save As button to copy an existing rule as a starting point for a new rule.

No comments:

Post a Comment

How to Deploy your API as a web app or API app

  Before you can call your custom API from a logic app workflow, deploy your API as a web app or API app to Azure App Service. To make your ...