Monday 25 June 2018

How to set a default form depending on attribute value in Dynamic CRM using JavaScript

Set desired form as default using script – CRM 2011

Description:
In this example we explain that how to set desired form as default form in Dynamic CRM using JavaScript. Or how to set Default Form in Dynamic CRM based on some condition using JavaScript. Or how to set Default form in Dynamic CRM at run time using JavaScript. Or how to set a default form depending on attribute value in Dynamic CRM using JavaScript.

In our requirement we have multiple Account form in our Dynamic CRM and we have to set default form based on some condition, so to achieve this solution we have created some JavaScript code to set the Default desired form in Dynamic CRM using JavaScript.

So below is the JavaScript code that will helpful to switch the form in Dynamic CRM at dynamically based on some condition.

Code: 

function setAccountFormAsDefault() {

            // Set the form name you want to set as default

            var DefaultFormName = "AccountInfo";

            // Get all available forms

            if (Xrm.Page.ui.formSelector.items.get())
            {

                var forms = Xrm.Page.ui.formSelector.items.get(); //give us all available forms of the current entity here we have Account

                var formId, formName;

                for (var indxForms = 0; indxForms < forms.length; indxForms++) {

                    formId = forms[indxForms].getId(); //gives the form GUID

                    formName = forms[indxForms].getLabel(); //gives the  Form name

                    // Check form name and if it matches set current form as Default

                    if (formName == myDefFormName) {

                        forms[indxForms].navigate(); //loads the selected form

                        break;

                    }

                }

            }

        }



0 comments:

Post a Comment