Contact

Industry Leading Blog for Manufacturers

Part 1 of a 3 part series: Using Business Rules

When developing customizations for Microsoft Dynamics CRM, forms can become cluttered with fields that are only used under very specific conditions. Take for example the following section from an entity form that deals with discount approvals:

entity form that deals with discount approvals

If a discount approval isn’t required, it doesn’t make sense to show the submitted and approved fields; they’re just cluttering the form. It would be preferred to hide these fields until they provide useful information to the user.

There are two possible ways to customize this form to dynamically show and hide these fields based on whether or not a discount is required: using business rules and using custom JavaScript. In this tech tip we will show you how to accomplish this with business rules. Next week we will describe how this can be done with custom JavaScript. In the final part of this series we will summarize the two methods and outline when to use each.

Using Business Rules to Show and Hide Fields

Business rules can be used to execute certain actions under a specific set of conditions. In this case, we want to show the “Submitted,” “Discount Approval Submitted Date,” “Approved,” and “Discounted Approval Approved Date” fields when “Required” is set to “Yes,” and hide the same fields when “Required” is set to “No.”

First, go to the form these fields are displayed on. Locate the fields you want to add showing and hiding logic to and open the “Field Properties” dialog for one of the fields. Navigate to the “Business Rules” tab:

showing and hiding logic in the “Field Properties” dialog

Click the “New” button to create a new business rule and launch the business rule creation dialog. Be sure to give the business rule a meaningful name and description.

In the business rule creation dialog you can see that business rules are broken up into conditions and actions. Actions define what the business rule actually does and conditions define when to execute the given actions.

Click the “+” under condition to add a new condition to the business rule. In this example, the condition we are checking against is if the “Required” field is set to “Yes.” Click the check mark to save the changes to this condition:

Discount Approval Display Logic for Business Rules

Click the “+” under action to add a new action to the business rule. In this example, when “Required” is set to “Yes” we want to show the “Submitted,” “Discount Approval Submitted Date.” “Approved,” and “Discounted Approval Approved Date” fields. Create a “Set visibility” rule for each of these fields:

Creating a “Set visibility” rule

Now that your business rule is complete, save the business rule, and activate it. Activated business rules cannot be edited; you must first deactivate the rule if you want to edit it. If a business rule is not active, it will not fire when the condition is met.

This business rule captures the “showing” portion of your showing and hiding logic. A separate business rule must be written for that same field to implement the hiding portion. Create a new business rule with the condition that the “Required” field is “No” and add actions to hide the “Submitted,” “Discount Approval Submitted Date,” “Approved,” and “Discounted Approval Approved Date” fields. Be sure to save and activate your business rule when you are complete.

Discount Approval Hide Logic

From your “Field Properties” dialog you should now have two active business rules:

Field Properties dialog box

With these business rules in place you are ready to test your showing and hiding functionality. Navigate to your form and test. When “Required” is “No,” the “Submitted,” “Discount Approval Submitted Date,” “Approved,” and “Discounted Approval Approved Date” fields should be hidden:

Discount Approval Not Required

Switching “Required” to “Yes” should cause the “Submitted,” “Discount Approval Submitted Date,” “Approved,” and “Discounted Approval Approved Date” fields to appear: 

Select Discount Approval Requirements

Limitations to Business Rules

It is important to note that there are a number of limitations to business rules:

  • In Microsoft Dynamics CRM 2013, else if and else clauses cannot be added. In Microsoft Dynamics CRM 2015 it will be possible to specify else if and else clauses in business rules.
  • You cannot conditions within conditions.
  • You cannot have “or” logic in conditions. To implement or logic you must create separate business rules.
  • You cannot group conditions.

 

Be sure to check back next week when we will demonstrate how to accomplish this same effect using custom JavaScript.


Stay up to date on the leading industry solutions by subscribing to our blog digest.
What can we help you with?

CONTACT US

(585) 506-4600