With other exciting features, Microsoft Dynamics CRM 2015 also introduced new following enhancement 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 which can help us in different business scenarios for example, let’s say you have one default pricelist that you want to set in opportunity, earlier we used to write retrievemultiple call to set default pricelist based on it’s name. But now we can simply design business rule to set default price list
Once activated, it will set default pricelist when 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 released for client side validation, but Microsoft Dynamics CRM 2015 added support to run these validation on server side as well, so now we can configure our business rule to run both client and server side. A new scope “Entity” is added in business rules designer which enables to run our business logic at server side as well, let’s take above example and activate it using Entity scope. Like below
Now let’s create opportunity using code, like below
private void Businesslogicdemo(IOrganizationService iorganizationService)
{
//Create entity class object and pass entity name
Entity opportunityEntity = new Entity(“opportunity”);
//call create method to create 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 opportunity record like following
Support for OR operator – Now business rule also supports OR logical operator, so we can have two condition and we can use And/OR logical operator between these conditions based on requirement.
Support for else – This is another new enhancement in business rules, earlier there was no support for else, so if you want to make any field required based on some condition in MS CRM 2013, you need to create two business rule one to make that required and another to make that field not required, but in MS CRM 2015 we can simply add else statement.
HIMBAP | Need any help in Microsoft CRM 2015 Contact US !!
Hi Mahender, These enhancements are really good! Especially the server side option is one that will make plugin code / integration complexity a lot easier.
Besides that I’ve a thought about the “set default value” option. Does this work over different / cross organization without changing the business rule manually after importing?
The reason why I think about this is because I worked a lot with business units, teams, queues etc. I have also written code to set default (active) pricelist to make sure the code / pricelist is not hard coded and doesn’t work cross environment. Because all entities mentioned above are records in the database and linked based on their unique GUID. When exporting customizations, teams etc. these links are broken because their GUID is different over all organization.
Look forward to hear/read from you. Thanks.
Thank you for your comment, Sorry for late response I was out for training, No it won’t work on cross organization, so you need to manually update it in your target organization. And regarding the code you should not hard code guid while writing code instead should write a retrieve call based on name so that it can fetch records based on name and fill it, and this will also work perfectly in your target environment, but you need to make sure to have the same record on target system. hope it will help. Thank you/
Hi Mahender,
No worries. I appreciate your response.
I prefer to work with a mark on the reference entity or settings entity so user can change the record of needed during time. With coding on name I can’t do that from my perspective?
But why not hard code guid in records for reference entities (like pricelists) we can export these records with the guid and import them in THE target.
Regards,
Nico
Yes, correct we can also create system setting and use it, Importing data is another option, but it will add one more step.
From my perspective iT will not add one more step, because you otherwise have to manually create THE record in all systems with risk of manual mistakes. Now you create THE records once and use the same export file as import source (only first time setup) over all environments.
But overall we agree on the possibilities we have and recognize that set default with business rules still force us to make changes to the target environment(s) after importing.
Thanks for your reply and the discussion!
Actually you are correct, instead of creating importing we will be good option at least there won’t be any possibility for any typo 🙂 Thanks
Pingback: Business rules enhancements in Dynamics 365 | HIMBAP
Pingback: Form and Fields Notification in Dynamics 365 Part 2 | HIMBAP