Improved Business Rules in Microsoft Dynamics CRM

Introduced in Dynamics CRM 2013, Business Rules enable logic execution to be applied to databases using in built tools which avoids the need, and expense, of writing custom scripting.

By configuring Business Rules, CRM is more prescriptive for users by dynamically enforcing conditions on forms and process flows based on the data entered in other fields.

Popular examples for Business Rules include controlling which fields and actions are shown on Cases record based after an initial product selection guiding users to a resolution. Also, Rules can be set to fire error messages on Lead records if invalid field entries are entered during the qualification process.

However, in the 2013 release these were subject to a few limitations.

Firstly, Rules would only support simple business logic. As a result, for many conditional logic rules administers would still need to resort to external coding.

Also, in CRM 2013 Business Rules were restricted to running on the client side only. For server side execution custom scripting would be needed.


Among the slew of improvements in the Dynamics CRM 2015 Update is a refresh to Business Rules which fixes this these restrictions and adds wider functions.

This includes:

• Support for enriched business logic including if / else
• Combining expressions using and / or conditional rules
• Using Rules to set default field values
• Synchronous server side Business Rule logic execution
• Visual editing

To illustrate how the ramped up Business Rules work in CRM 2015 let’s take an example using the new if / else logic.

In this scenario we want to set a Business Rule on a Quote record that will automatically set the Quote Discount Value to 10% if the total quote amount is greater than £10,000. For all quotes below this threshold the default discount will be 5%.

To achieve this we’ll set a new Business Rule that will apply to the Quote entity:

Firstly, a condition has been set if the total quote amount exceed £10,000.

Next, an action needs to be defined that will be enforced for all Quotes that trigger this condition.

In CRM 2015 there are 6 Business Rule operations available in the 'Actions' lists.

Show Error message: Field validation check alerting the user with an error message if an entry breaches defined conditions
Set Field Value: Automatically setting the value of the field on the form
Set Business Required: Used to set a field as mandatory
Set Visibility: Show / hide fields based on conditions
Set Default Value: Applying a default field value
Lock or Unlock Field: Setting field write permissions

In this example we will select ‘Set a Field Value’



We can now go ahead and select the ‘Quote Discount %’ field and apply our defined 10% mark down that will automatically be applied for all quotes that match the above condition.

Using the new CRM 2015 functions a further ELSE condition can be set that will apply to all records which don’t trigger the previous rule.

In this example, an ELSE condition has been configured to set a 5% discount for all quotes that total less than £10,000.

CRM 2013 lacked support for IF…THEN…ELSE logic so for this particular example it would require 2 separate Business Rules to be defined for both eventualities.

Server Side Business Logic Execution

Another improvement to Dynamics CRM Business Rules is server-side execution that enables a synchronous workflow to be executed.

As well as being a real-time operation this offers greater control by defining the scope that will be set to the entity.

This also ensures your rule will fire no matter how CRM records are updated, even if fields are automatically updated via integrated solutions.

To demonstrate, let’s take an example where you have one synchronous workflow that controls the process to automatically create contacts when an account is created. Then we'll create a business rule that will prevent users from creating contact records when the parent Account record has a Country field set to “US”.

Applying this scenario to CRM 2013 using a workflow and business rules, Dynamics would still create a contact record and only when this record was opened would an error message be seen.

In contrast, by using server side Business Rules in CRM 2015 far greater control can be applied which will immediately roll-back by firing an error message on the parent entity if the Business Rule is violated at the child entity.

To demonstrate this feature, we’ve outlined the steps needed.

1. Firstly, we’ll create a synchronous workflow that will automatically create a new contact when an account is created.

2. Next, a contact based Business Rule will be added with the Scope set to the whole ‘Entity’ i.e. ‘Contacts’ that will execute the business rule on server side.

If required, the scope could be narrowed to selected forms. This offers greater precision in controlling how the Rule will be applied so can prove useful if a Business Rule will only apply to a specific team who work with their own dedicated form.

3. Now the scope has been set we need to specify the condition and error message that will fire if this condition is violated.

Using this basic rule a condition has been set to check the contact ‘Country’ field for entries that equal ‘US’.

If a match is found it will fire an error message.

4. After activating the Workflow and Business Rule, if a user attempts to create a new parent account with the Country set as ‘US’ CRM fires the following error.

In comparison to CRM 2013 neither the account, nor a contact record will be created...

If you’d like to find out more about Dynamics CRM Business Rules and discuss how these can be applied to your own database we’d be delighted to hear from you.

Demonstration

Click here to see a demonstration of the improved business rules and other improvements in the Dynamics CRM 2015 update.