Hi All,
I have two Contact forms namely "Contractor" & "Agent Contact" and I have a attribute to store the type. When a user open a contact, based on the selected contact type (i.e. Agent/Contractor) I need to switch the form with script. The one I use below worked fine in CRM 2011. However, in CRM 2013 I am getting errors like "Unable to get property 'add_afterSelect' of undefined or null reference", "Unable to get property 'get_isDisposed' of undefined or null refence" & etc... Deployed below code alone (without any other customizations) in a brand new trail edition and got error in that as well...
Code that I used is:-
var FORM_TYPE_CREATE = 1; var FORM_TYPE_UPDATE = 2; var AGENT_CONTACT = "1fed44d1-ae68-4a41-bd2b-f13acac4acfa"; var CONTRACTOR = "2ef6278d-1f25-45e4-9da6-7037fe126b63"; function OnFormLoad() { formSelector(); } function formSelector() { if (Xrm.Page.ui.getFormType() == FORM_TYPE_CREATE) { ContactTypeChanged(); } else if (Xrm.Page.ui.getFormType() == FORM_TYPE_UPDATE) { // Current form name var currentFormName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel(); // Form type var type = Xrm.Page.getAttribute("new_contacttype"); // Disable navigating to different form type Xrm.Page.ui.controls.get("new_contacttype").setDisabled(true); // logic if type and form name dont match if (type.getText() != currentFormName) { switch (type.getText()) { case "Agent": case "Agent Contact": Xrm.Page.ui.formSelector.items.get(AGENT_CONTACT).navigate(); break; case "Contractor": Xrm.Page.ui.formSelector.items.get(CONTRACTOR).navigate(); break; } } } } function onChangeType() { // Current form name var currentFormName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel(); // Enable Contact Type optionset to set different form type Xrm.Page.ui.controls.get("new_contacttype").setDisabled(false); // Change form type switch (currentFormName) { case "Agent Contact": Xrm.Page.getAttribute("new_contacttype").setValue("2"); break; case "Contractor": Xrm.Page.getAttribute("new_contacttype").setValue("3"); break; } // Disable Contact Type optionset Xrm.Page.ui.controls.get("new_contacttype").setDisabled(true); }
If I Change
function OnFormLoad() { formSelector(); } to function OnFormLoad() { setTimeout(function () { formSelector(); }, 1000); } it work fine without any errors... With this method there may be possibility of getting same error if the internet connection is slow.
Any suggestions.