Business rules enhancements (2015)

rulesyoucanyoucanttwice
The Business rules feature was first introduced in the 2013 version.
Business rule gave users the ability to perform simple client-side form validations(Main and Quick Create forms) and actions such as
showing,hiding,enabling and disabling fields,Making a field as business required,Calculating the value of a field based on the other fields value,
showing error messages based on an invalid input,and setting values to fields, all without the aid of a skilled developer or any code experience.
However business rules in CRM 2013 had few drawbacks.
As said business rules in 2013 was available only on client-side ,if an SDK action was made the business rule was not executed which required duplicate logic implementation in server-side to achieve the same behavior.
Another drawback was the trigger for the taken action.
In 2013 only if all the business rule conditions were true then the action was executed,meaning single IF condition.
There were now if…else statements ,which required defining many business rules to achieve complex rule.

In Crm 2015 we can now use an If…Else (or else if) statement
So lets take a scenario where we want to set an opportunity discount according to total amount.
If the amount in “Total Detail Amount” is less than 1000 don’t set the “Opportunity Discount” to 0.
if the amount in “Total Detail Amount” is between 1000 and 15000 set the “Opportunity Discount” to 10.
Else, if its greater than 15000 set it to 12.
In prior version we had to define three different rules but now in 2015 this is how it would look.
First we’ll define if statement to set 0% discount if the “Total Detail Amount” is less than 1000.
Next we will add else if statement to set 10% discount if the “Total Detail Amount” is greater or equal to 1000 and lower or equal to 15000.
And finaly add else statement (achieved by not filling an IF condition but only an action) to set 12% discount
br1

As we said in CRM 2013 the business rules were only applied on the client(UI) in CRM 2015 we can choose whether the rule scope will be on the server and the client by choosing the Entity scope.
The other options are same as in CRM 2013.
br2
Note that business rules order will execute after all synchronous plugins will be executed since business rules are in fact synchronous workflows.
The order of business rules execution is by activation time form oldest to newest so you can control the execution order by deactivating and activating business rules in the required order

Published by Yaniv Shoval

.Net developer who takes interest in various technologies but specialized in .NET and Microsoft Dynamics CRM development

Leave a comment