Search This Blog

Tuesday, October 4, 2022

Business Rules in CRM

 What are Business Rules?

–          In CRM 2013, the Business Rules are introduced to allow end users to apply basic form logic without writing JavaScript in CRM

–          It provides simple declarative interface to implement


What things are possible using Business Rules?

–          Hide/Show fields on the form

–          Set field values

–          Enable/Disable fields

–          Set field requirements

–          Validate data and show error messages


4 ways to configure Business Rules

–          Solution -> Entity -> Business Rules

image

–          Solution -> Entity -> Field

image

–          Form Editor

image

–          Form Editor -> Field (Field Properties) -> Business Rules

image


How Business Rules work?

–          Business rules are applied based on the scope of the business rules selected during creation. Only activated business rules will be applied on the respective entity forms.

–          By default the scope is set to All Forms. To make the business rule available to specific form, you need to change the scope of the business rule.

image

–          In below order the logic is applied to the form field:

1. System Scripts

2. Custom JavaScript

3. Business Rules

Note: If there are multiple Business Rules applied on single field, then the rule in the order in which rules are activated. Hence if you want any business rule to be applied first, then you need to activate that rule at the last.


How to edit existing Business Rule?

To edit existing Business Rule, first deactivate the rule and then edit. To apply the updated logic, you will need to activate the rule again.


Advantages

–          Allows end user/ CRM customizer to apply logic quickly without writing any code

–          Enabling and Disabling of logic is simple

–          Easy to test the written logic by Preview option on the Form


Limitations

–          No complex logic is supported.

–          Business Rules does not run on Form Save event. They only run on Form Load and Field Changes.

–          Custom JavaScript event on the ‘OnChange’ event of field will not work if you set field value using Business Rules.

–          The rule will not run if the field mentioned in the rule is not available on the form. It will not throw an error. Hence user will not come to know about the error.

–          Business Rules does not work on Tabs/Sections/Sub Grids etc.

–          Does not allow else condition. Hence to apply If Else logic, you need to create separate business rules for each condition.

–          Only AND logic can be applied in the Business Rule. No OR logic.


How to setup logic in Business Rules?

Business Rules are divided into 3 sections:

–          Conditions

a. Conditions can be checked on fields only

b. Below operators are available

image

–          Actions

Actions are the tasks that can be performed by the Business Rules. Actions will be performed only if all conditions are true.

o   Show error message: Used to show any custom error message on any field based on the condition. This does not allow the form to save.

o   Set field value: Allows to set value to any field.

o   Set Business Required: Allows to set any field either required or not required.

o   Set visibility: Allows to show/hide the field.

o   Lock or Unlock field: Allows to make field read-only or editable.

–          Description (Optional)

Gives description of Business Rule. This is optional and does not appear anywhere else.


Examples

–          Assumptions:

I have custom entity named “Business Rules Demo” with below fields:

– Field 1 – Two Options

– Field 2 – Option Set { A, B, C, D }

– Field 3 – Single Line of Text

– Field 4 – Single Line of Text

– Field 5 – Single Line of Text

  1. If Field 1 = True

Then

Hide Field 3

Make Field 4 Required

Set Field 5 to ‘Hello’

Disable Field 2

Show error message on Field 1 as ‘Field 3 is hidden’

Else

Show Field 3

Make Field 4 not required

Set Field 5 to ‘Bye’

Enable Field 2

For this, we need to create 2 business rules; 1 for If part and other for Else part as below:

image

image

Note: To copy the business rule, open business rule and use ‘Save As’ option. This will create copy of the business rule.

Custom error message will be shown as below:

image

  1. To check if any field is blank or not, use Contains Data and Does Not Contain Data operator in the condition.

References

http://technet.microsoft.com/en-us/library/dn531086(v=crm.6).aspx


No comments:

Post a Comment