Adding Business Logic to your Dynamics 365 Forms

Visit Website View Our Posts

JavaScript and Business Rules

Are you considering a new project with Dynamics 365 or looking to upgrade from an old version of Dynamics CRM/AX?  In Dynamics 365, both JavaScript and Business Rules allow you to add business logic to your forms. For example, you can use them to conditionally hide fields, set default values or enforce field requirements.


Both JavaScript and Business Rules work in a variety of environments outside of the native Dynamics 365 web browser version. This includes Dynamics 365 for tablets and even the Dynamics 365 Outlook app (online or offline mode). However, you should be aware of some recognized differences and limitations of each.



JavaScript requires a developer and involves adding logic to a form that executes in real time from the end users machine. Developers commonly use it to perform functions that manipulate form elements, such as conditionally hiding/showing fields or enforcing field requirements. This logic can also include changing the value of fields. For example, developers may code it to clear the value of fields once they are hidden on the form. Developers still use JavaScript today, both in Dynamics 365 and elsewhere! However, you should be aware of some well-known issues experienced with the use of JavaScript:


The behavior can be different, based on inconsistencies in each end user’s environment (which are difficult to regulate!). This can be true even if the app provider says it’s compatible. While solution providers try their best to make everything compatible in most common environments, there are sometimes noticeable differences in behavior. Even worse, it may not be compatible at all in one users’ environment and therefore not execute.
It requires a developer to code and maintain as your business logic changes.

Business Rules

We’ve written a few blogs about Business Rules since they were first introduced in Dynamics CRM 2013, but they have since evolved! Business Rules can replace some JavaScript and they require no coding knowledge. Microsoft provides a simple, declarative interface that your system administrator can use to create a business rule. However, they do require an understanding of both form logic and your business needs.
An added benefit over JavaScript is that you can toggle their scope to either work from just the form level or also from the entity level. The entity level enables the rules to run from the server level. This is a nice benefit to organizations that utilize external apps which automatically sync or create records in CRM in the background, such as mobile apps. It ensures that your business logic will continue to execute even if the end user is not creating the record within CRM. With all of these benefits, there must be some limitations, right?!  Some important limitations of business rules to keep in mind are:


Business Rules will always run when a form loads and the associated field value changes. With JavaScript, you have more flexibility. For example, a developer can configure it to only run when a field value changes or when the record is saved.A scenario where this is important to keep in mind: You have JavaScript that executes on change of a field which then hides other fields and clears their values. You then replace that JavaScript with a Business Rule. Because of the limitation mentioned above, the logic will now also run when the form is loaded. Business Rules haven’t evolved to determine whether a field value is already cleared, so it executes every time. The result? Your end users experience this annoying error closing out of the record, even if they haven’t made any changes:
JavaScript and Business Rules


Business Rules can only interact with fields. You cannot use them to to specify hiding/showing of entire tabs/sections. A workaround to this would be to hide all fields within that tab/section, but that can be cumbersome with many fields on evolving forms. In this scenario, JavaScript may be easier to implement.
Any JavaScript that fires OnChange of a field will not execute if the field value was changed by a Business Rule. For this reason, it is often recommended not to combine Business Rules and JavaScript. However, this is not always feasible, so it is important to keep in mind.
If a Business Rule references a field that has been removed from the form, the rule will not run and an error will not appear. This could also be seen as beneficial, depending on your situation.
Business Rules are cached on Dynamics 365 for tablets. If your System Administrator/Customizer changes the logic, this will not be committed to tablet users until they close and re-open it.  Most of the time, this should not be an issue unless you have users who work 24/7!

New features of Business Rules

Check out what you can do with Business Rules in the latest update from Dynamics 365.


Two that I think are worth highlighting include:


Create a snapshot of an entire Rule. You can use this to share with your team members for input before it is committed to the system.
Create business recommendations based on business intelligence. This adds helpful tips next to fields to guide users on filling out forms based on previous data filled in.  A great example provided in Microsoft’s blog is the use of these for product recommendations. For an example, an end user may be filling in a new Opportunity for a prospect. Based on previously identified information such as their age and insurance type, a recommendation can be made for products that other prospects within their group typically purchase.


Beringer Technology Group, a leading Microsoft Gold Certified Partner specializing in Microsoft Dynamics CRM and CRM for Distribution. We also provide expert Managed IT Services, Backup and Disaster Recovery, Cloud Based Computing and Unified Communication Systems.

Show Buttons
Hide Buttons