Business Rules in Dynamics CRM are a way to implement Client Side business logic through the user interface & was originally introduced in CRM 2013. They are quite nifty little things and can prove to save time and effort as opposed to writing JavaScript to do the same thing. Of course, it does depend if you can do the same thing in Business Rules, as that is where it’s limitations are. Originally in the CRM 2013 implementation, you could only build linear logic through business rules that resulted in showing an error message, setting a field’s value, set business required, set visibility or lock/unlock a field.

Whilst limited, those actions are still very useful as they are what could possibility be described as ‘lightweight’ tweaks that provide a much better user experience whilst at the same time implementing a more defined business process for clients which can be implemented without needing to create a JavaScript function to do the same work for you, bonus! However there is a couple of drawbacks, however I don’t think they are deal breakers – because in the original implementation you could only build linear logic e.g. If a=b then do this, and if ‘this’ included something like ‘show a field’ for example, you had to build a second business rule if you wanted to hide that field again if you required the client to re-evaluate the logic because the fields have changed since the first time it processed the business rule (whilst in JavaScript, you could have a function operating onChange of a specific field). The second drawback is you can only have a business rule operating on all forms, or single forms. If you have 5 forms and require a rule to be present on 2 out of those 5, you need set your business rule to operate on one, save a copy, then set that copy to run on your second form.

I think that by being aware of these drawbacks of this functionality you can still create effective business logic that is very very quick and also less prone to error rather when compared with writing custom code, therefore more supportable in future upgrades.

BusinessRulesMain

New Options that have been added to Business Rules for CRM 2015

The fantastic news is that in CRM 2015 Business Rules have been greatly improved, they are pretty awesome now and one of the drawbacks I mentioned above have been taken care of from this new awesomeness. Old Business Rules used to be linear business logic, now they have the option to be branched business logic.

They achieve this in a number of ways, the two major points are listed below.

1) There is now the possibility to ‘+ Add Else’ after you have began constructing your first section of logic. If you were to then only to create one branch, if it effectively an IF ELSE statement, however you can go even further than that and add a Second branch and so on which become ELSE IF additions to your logic. You can see this in the image above.

2) Not only can you add branches but you can specify the conditions AND & OR on your conditions as well. So your first section could be If Account Name contains ‘A’ AND If Account Name contains ‘B’ then do X else If Account Name contains ‘C’ OR If Account Name contains ‘D’ then do X. The important thing though is you cannot have one condition with both and & or it has to be one or the other.

andor_functionality_2015

AND/OR functionality added in to conditions

businessrules_optionsstart

Left: The starting screen for Business Rules in CRM 2015 & Right: The starting screen for Business Rules in CRM 2013

By opening up Business Rules to be capable of branching you no longer have to deal with linear logic and the result is you can make some very powerful client side logic. You no longer have to construct ‘opposite’ rules and can deal with these in ‘else & else if’ statements, meaning your business logic is in one rule as opposed to two or more. However, with great power comes great responsibility, I recommend to not be complacent just because you don’t have to write code. Business Rules still need implementing correctly and because they have effectively become more complicated with this additional functionality, whilst that is an amazing thing, you need to think about the branches and what they could mean for your user experience so still need to be fully tested.

On an ending note, whilst I was playing around with the new business rules I also found they have added a new action you can perform that was not present in CRM 2013 – ‘Set Default Value‘. This could be useful as the end of your branching business logic, a bit like the ‘default’ branch of a switch statement.

20152013Diff

Additional Option ‘Set Default Value’ has been added in Business Rules for CRM 2015