What I really hate about CRM development is that sometimes you need to duplicate the code both in UI and on a server side.
For example, when you need to calculate something on a form. In this case, you have two options to choose:
- Writing a Plugin that will calculate these values upon data saving.
How Microsoft CRM 2013 can change the game
How Actions can help to move all business logic into a managed code
OnSave event is not required here because all calculations and validations occur during OnChange events processing. This insures quick response to the customer’s data and actions.
Finally, I wrote a plugin that executes Business Rules implementation on a Server side:
So, as you can see, the only thing we need is just to change and support Business Rules classes and they will work on Server and UI side with no extra efforts.
Let’s take a closer look to Pros and Cons of this solution.
- Performance loss for small JS without server interaction.
If you need just a small script that works with the form data only, you’d better write it in a pure JS as in this case it ensures faster logic performance. But once you add JS interaction with the server (request additional data, check user role names, etc.), it is the server-side logic that begins to win the performance competition.
- No need to describe the behaviour, just logic.
- Easy change management as you write the code for server-side only, so all changes are done in one place. No hidden dependencies.
- Same pattern for different developers. All developers will use the same pattern to write code, so it should also lower maintenance costs.
To find more information, please, view the presentation.
MS CRM 2015 announced that it would support server side Business Rules, finally, they understand that :). Unfortunately, it will support limited functionality and will not support custom code. But I think in future releases they will remove obsolete Plugin approach