CRM 2013 – Understanding Business Rules

What are business rules

Business rules were added to CRM 2013 and a way to provide client side scripting/validating/field or section hiding without having to write any JavaScript.  For context server side customization’s are plugins/workflows (e.g. code written in C# is executed on the server)

Business rules are also known as portable business logic (although I don’t know anyone who calls them that) because they also work on the mobile app.

What can business rules do

  • Set field values
  • Show/hide fields – Visibility
  • Enable/disable fields
  • change the requirement levels on fields (e.g. business required, recommend)
  • Show error messages

All the features above were usually done using Javascript in CRM 2011.

I have written a quick guide to business rules here

Why are business rules useful

Business rules are useful because they allow non developers to provide the functionality mentioned above on forms.  Business rules can be used on Main and Quick Create Forms.


Are there any Business Rules Gotcha’s

You bet there are, here are the main ones

  • Fields updated using business rules do not trigger the fields on change event!
  • Business rules run only when the form loads and when field values change. They do not run when a record is saved.
  • Business rules only work with fields on the form (and the first 75 for tablets)
  • Business rules run only when the form loads and when field values change. They do not run when a record is saved.
  • Business rules are run in order of activation
  • Business rules only work client side, so won’t be triggered when data is changed server side (plugins, workflows, import)
  • Logic in business rules is appliedWhen there are multiple business rules, they are applied in the order they were activated, from oldest to newest.


There is also a big logical error which can be added using business rules and this is when you have either

Conflicting business rules

JavaScript and Business rules conflicting

Business rules will now mean there is an extra area to check when things are working in an usual many.  Entities could have Javascript, multiple business rules, Workflows and plugins all updating the same fields.  The possibilities are endless and so are the potential bugs.

As a general rule I would advise people not to mix JavaScript and business rules because it will make the solution more complex for developers to understand and maintain.  Developers will also need to understand JavaScript will run first and then business rules (if the condition is true)


How do business rules work

Business rules are created on an entity basis

Business Rules

Business rules come in two parts, the condition and the action.

The condition is the criteria for the business rule to test to see if it runs.  Currently business rules can have more than one condition and they work on an AND basis (e.g. all conditions have to be true).

If the condition is successful, then the action will execute.

Business Rules 1

You can view business rules a bit like real time workflows, but the actions can show/hide, enable/disable fields and show error messages etc.

Business rules also run only on the client side (e.g CRM FORM), which means they can only be triggered when adding/editing data on the CRM form.


Schoolboy error

Business rules usually have to be created in pairs and most people when they first use business rules they only create one.

You don’t need two but you usually do.  If you hide a field/section with a business rule then you need another business rule to show the field/section otherwise it’s always hidden

To read more about this, read the blog post below

CRM 2013 – Business Rules work in pairs because the condition is AND and not IF


Running Order

You could have a lot of things running on a form such as JavaScript and numerous business rules so you need to understand in what order things will run.  It’s possible you could have JavaScript and numerous business rules all running against one field, so the order things run can have a dramatic effect on the outcome.

According to this MSDN article on business rules

The logic included in your business rules is applied together with other logic in the form that could include system scripts, custom scripts, and other business rules. The order in which this logic is applied will affect the outcome. The order is as follows:

  1. Any system scripts are applied first.
  2. Any logic in custom form scripts is applied.
  3. Logic in business rules is applied.When there are multiple business rules, they are applied in the order they were activated, from oldest to newest.

This means that to control the order in which business rules are applied, you must deactivate and reactivate the ones you want to be applied last.


I guess there isn’t any real way of knowing what Systems scripts are running or what they are doing so I will ignore those.

Javascript will run first

Business rules are run in order of activation.  This sounds like a painful process of having to deactivate business rules and activate them in the order you want them to run (surely there must be an easier way), I can see some very tricky bugs to find


Business rule Scope

A bit like workflows, business rules have a scope but business rules are only concerned with forms.  The scope choices are

All Forms

Choose one of the main forms


If you choose all forms, the business rule will run on the main form and Quick Create form but you cannot individually choose a Quick Create form.

Interesting thing to understand

Business rules get converted in JavaScript by CRM and then applied to the form.  Business rules only work client side (not server side like workflows and plugins).  The downside to this is business rules only get triggered on the form and not if the data is updated by any other means (bulk update, plugins, etc)


CRM 2015 – Business Rules enhanced

Business rules are going to be upgraded in CRM 2015 and I have seen it nicely put as Business rules enhanced

 IF, THEN and ELSE Conditions

The biggest enhancement to business rules will be the adding of if statements.  At the moment conditions must all equal true, this means you have to create two business for most functionality (e.g. one business rule to show a field and another business rule to hide a field)

Here is a good article on the new IF, THEN

And/or support

Conditions in business rules CRM 2015 will all combinations of AND or OR, with the limitation of only using them in one/single condition, so it’s a bit better.

Set Default Value

A business rule to set default values for fields

Server side

Business rules will be able to work server side.   The reason this is important is because it means business rules won’t only work when the entity and fields are updated using the CRM form but also when bulk updates, imports or plugins changes those fields.


What hasn’t been fixed in CRM 2015

CRM 2015 business rules will be enhanced but they won’t be totally awesome yet, there will be a few errors which could still do with some improvement.

Complex conditions

Conditions have been improved but they are limited to one If/Else in a condition.

Hide/Show Sections and Tabs

I don’t think you can hide/show sections and tabs in the CRM 2015 enhanced business rules.

Cannot clear a field

You can set a default but you cannot null or clear a field using business rules

Related entity fields

One of the great things about work flows is you can update related entities specified in a lookup field, this would be great in business rules and save people do this using OData calls in Javascript.


Formula’s could be enhanced.  E.g. dynamic dates can only be created by adding on days (not hours)



Further reading for CRM 2013 Business rules



Visual Studio 2012 keeps crashing

Visual studio has kept crashing for 3 developers over the last few weeks.

What makes it worse is there doesn’t seem to be any consistency to the cause of the crashing, it sneaks up suddenly and POW, freezes and crashes before kindly offering to reopen for you.

What made it more confusing/annoying was no could reproduce the crashing constantly, some days you would have a few days without crashing and then one day it could crash 10 times and ruin your day.


We found a solution which seems to work

(backup first) – ALWAYS

then delete the ComponentModelCache folder, which you should find here



The solution doesn’t seem to shed much light on what was causing the crashing, particularly the fact it was happening to different developers on different computers.