Set desired form as default using script – CRM 2011
I have an “Account” entity with multiple forms (i.e.,4 forms). My requirement is to set particular form as default form based on some logic.
Below is the script to set desired form as default.
function setMyFormAsDefault() {
// Set the form name you want to set as default
var myDefFormName = “ABC”;
// Get all available forms
if (Xrm.Page.ui.formSelector.items.get()) {
var forms = Xrm.Page.ui.formSelector.items.get();
var formId, formName;
for (var indxForms = 0; indxForms < forms.length; indxForms++) {
formId = forms[indxForms].getId();
formName = forms[indxForms].getLabel();
// Check form name and if it matches set current form as Default
if (formName == myDefFormName) {
forms[indxForms].navigate();
break;
}
}
}
}
- “Xrm.Page.ui.formSelector.items.get()” give us all available forms of the current entity
- getId() & getLabel() gives the form GUID and Form name
- “navigate()” loads the selected form
🙂
Categories: CRM 2011, JScript
CRM 2011, default form, JScript, multiple forms
do you call it setting default form, will it prevent re loading form if the user chooses a different form??
Every “Navigate()” causes reload of the form.
If I have multiple forms do I need to put this script on the OnLoad event for all of the forms (except default one)?
Hi,
Script has to be registered on your first form based on the order.
So by default form configured first in the order loads and the script kicks in and navigates the user to your desired form.
FYI, We can specify the order of the forms using ‘Form Order’ option. Note that forms visibility depends on the user’ role.
Thanks,
Rajeev