Tag Archives: dynamics crm switch forms dynamically client script

Switch Forms in Microsoft Dynamics CRM depending on Business Logic

Recently in our project, we had a requirement where the customer wanted to show different forms of the same entity depending on some business logic. Off-course we could design the form with multiple sections with appropriate fields and show/ hide the sections based on business logic.

However if the above approach does not suit you, you have the Xrm Scripts in CRM 2011 and CRM 2013 to enable you to switch forms dynamically. Please check for the pseudo code below. All you need to to set up a default form for the entity. In the default form load check your logic and perform the redirection as required.

var formId= “<Id of the form to navigate>”

if( logic == true )
{
   Xrm.Page.ui.formSelector.items.get(formId).navigate();
}

To get the Id of the form to navigate to, you can write the following code in the onload of the form and copy it and use it in the default form.

var currentFormId= Xrm.Page.ui.formSelector.getCurrentItem().getId( );

Please note that getCurrentItem() method would not work for Microsoft Dynamics CRM for tablets.

 

Hope this helps!