CRM 2011 introduces the out of the Role Based UI (RBUI or RBF for Role Based Forms). It is a very nice feature and frankly, it was about time they introduced it. Obviously, it is limited because we can only display a form based on CRM user’s security roles. A very common request is to display a specific form based on field value(s). Example could be showing different opportunity forms based on the stage. Here I am sharing a couple of ways to achieve this.
Client Side Solution: The idea is to have a Jscript method that executes when the form is loaded. It reads the ‘decision’ field(s) value(s) and navigates to the appropriate form using the Xrm.Page.ui.formSelector item navigate()
method. A very clear and simple example of that is available here.
- It is 100% supported
- Work on all types of installations (CRM Online, On Premise, ADFS)
- Introduces a visible “refresh” after the form is loaded when a redirection is required
Selecting another form manually is no longer possible (you are always redirected to a specific form)
Server Side Solution: This is a little bit more complicated to set up. We did it by using a custom IIS rewrite provider. It means writing some code that
- Reads the record ID and type name or type code from the URL
- Loads the record from the CRM DB
- Reads the “decision” field(s) value(s) and redirects to the appropriate form if required
These steps sound pretty simple but there are a few things to take into consideration. In order to load the record from the CRM DB, you need to have CRM context information to connect to CRM which you don’t necessarily have from the IIS rewrite custom provider (it is executed from the GAC). In addition to that, you need to make changes to the CRM web.config file to add a rewrite section pointing to your custom rewrite provider. You can find more information on how to set up the custom rewrite provider here. If you want a concrete example, you can comment here or contact me directly (no code sample today!).
- No visible “refresh”, the redirection is made directly on the server
- It is complicated to setup and requires an unsupported step (modifying CRM web.config)
- Only works for On Premise installation
- Selecting another form manually is no longer possible (you are always redirected to a specific form)
In both cases, remember that you can hard-code the IDs of the forms in your script or C# code because they remain the same as you go from one environment to another (i.e. forms are transported in CRM solutions with their ID) so there is no additional work required for this. Given the choice, I would always go for solution one (client side script) even if it introduces a visible refresh at times. Unfortunately, sometimes that refresh is not acceptable from a client’s perspective so you have to be creative and come up with other approaches like the IIS URL rewrite custom provider.