With other exciting features, Microsoft Dynamics CRM 2015 also introduced the following new enhancements in business rules:
- Set default value
- Support for Server-side logic
- Support for OR operator
- Support for else
Setting Default Value
This is a very useful enhancement that can help us in various business scenarios. For example, let's say you have one default price list that you want to set in opportunity, earlier we used to write retrievemultiple call to set a default price list based on it's name. But now we can simply design a business rule to set the default price list.
Once activated, it will set a default pricelist when the opportunity record is created.
This is especially useful to set some default value to required fields automatically.
Support for Server-side logic
Initially business rules are released for client-side validation, but Microsoft Dynamics CRM 2015 added support to run these validations on the server side as well, so now we can configure our business rule to run both on the client and the server side. A new scope “Entity” is added to the business rules designer that enables us to run our business logic at the server side as well. Let's use the preceding example and activate it using Entity scope as in the following:
Now let's create an opportunity using code, as in the following:
- private void Businessruledemo(IOrganizationService iorganizationService)
- {
-
- Entity opportunityEntity = new Entity("opportunity");
-
- iorganizationService.Create(opportunityEntity);
-
- }
Please note we are not adding any attribute value, but as soon as this code is executed it will also run our business logic and our default values will be available in the opportunity record like the following:
Support for OR operator
Now business rules also support the or logical operator, so we can have two conditions and we can use the And/OR logical operators between these conditions based on requirements.
Support for else
This is another new enhancement in business rules, earlier there was no support for else, so if you needed to make a field required based on some condition in Microsoft CRM 2013, you had to create two business rules, one to make that required and another to make that field not required, but in Microsoft CRM 2015 we can simply add an else statement.
HIMBAP | Need any help in Microsoft CRM 2015 then contact us!