Answered by:
Switching from one form to another though Script

Question
-
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.
- Edited by Ajai.CRM Tuesday, February 18, 2014 10:30 AM Edited
Tuesday, February 18, 2014 10:25 AM
Answers
-
Unfortunately no response. Hence I guess this is KNOWN BUG in CRM 2013.
So, only possible solution is,
function OnFormLoad() { setTimeout(function () { formSelector(); }, 1000); }
Thanks
Ajai
- Marked as answer by Ajai.CRM Thursday, February 27, 2014 6:38 AM
Thursday, February 27, 2014 6:38 AM
All replies
-
Hi,
I have solutions that change the form immediately in CRM2013 which work fine.
I suspect that the issue is that you have some other scripts that are running after the form navigate - these will then fail because the form is in the process of changing. The reason it works with the setTimeout might be because this gives the form scripts time to complete before navigating.
Hope this helps,
Scott
Scott Durow
Blog www.develop1.netFollow Me
Rockstar365
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"- Proposed as answer by Scott Durow (MVP)MVP, Editor Wednesday, February 19, 2014 11:57 AM
- Unproposed as answer by Ajai.CRM Friday, February 21, 2014 5:57 AM
Wednesday, February 19, 2014 11:57 AMAnswerer -
Hi,
Unfortunately it seems you have NOT read my entire post...I tried that, I infact posted about that in above post...
Deployed below code alone (without any other customizations) in a brand new trail edition and got error in that as well...
Thanks
Ajai
- Edited by Ajai.CRM Friday, February 21, 2014 5:59 AM
Friday, February 21, 2014 5:58 AM -
Hi Ajai,
I used the following code in new trial edition and its working fine without any error message.
var FORM_TYPE_UPDATE = 2; var CONTACT = "1fed44d1-ae68-4a41-bd2b-f13acac4acfa"; var Information = "1f9c9eda-1cef-4cde-aabb-db96f389ebe2"; function OnFormLoad() { formSelector(); } function formSelector() { 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"); // logic if type and form name dont match if (type.getText() != currentFormName) { switch (type.getText()) { case "Contact": Xrm.Page.ui.formSelector.items.get(CONTACT ).navigate(); break; case "Information": Xrm.Page.ui.formSelector.items.get(Information).navigate(); break; } } } }
puja jain
Friday, February 21, 2014 6:59 AM -
Error report for Microsoft generated by CRM is,
Microsoft Dynamics CRM Error Report Contents <CrmScriptErrorReport> <ReportVersion>1.0</ReportVersion> <ScriptErrorDetails> <Message>Unable to get property 'length' of undefined or null reference</Message> <Line>5</Line> <URL>/_common/global.ashx?ver=-507387479</URL> <PageURL>/main.aspx?etc=2&extraqs=%3f_gridType%3d2%26etc%3d2%26id%3d%257bA5B51CE5-3A92-E311-B0AE-6C3BE5BE5E68%257d%26rskey%3d516869557&pagemode=iframe&pagetype=entityrecord&rskey=516869557</PageURL> <Function>anonymous(a,b){a[a.length]=b}</Function> <CallStack> <Function>anonymous(a,b){a[a.length]=b}</Function> </CallStack> </ScriptErrorDetails> <ClientInformation> <BrowserUserAgent>Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; Zune 4.7)</BrowserUserAgent> <BrowserLanguage>en-US</BrowserLanguage> <SystemLanguage>en-IN</SystemLanguage> <UserLanguage>en-IN</UserLanguage> <ScreenResolution>1920x1080</ScreenResolution> <ClientName>Web</ClientName> <ClientTime>2014-02-21T12:34:48</ClientTime> </ClientInformation> <ServerInformation> <OrgLanguage>1033</OrgLanguage> <OrgCulture>1033</OrgCulture> <UserLanguage>1033</UserLanguage> <UserCulture>1033</UserCulture> <OrgID>{31A5A50D-DA5A-4037-A8CD-29944E2E883C}</OrgID> <UserID>{6E7D593C-38CD-449F-84F0-EBFE72CEEEDB}</UserID> <CRMVersion>6.0.1.462</CRMVersion> </ServerInformation> </CrmScriptErrorReport> <CrmScriptErrorReport> <ReportVersion>1.0</ReportVersion> <ScriptErrorDetails> <Message>Unable to get property 'get_element' of undefined or null reference</Message> <Line>1157</Line> <URL>/_common/JsProvider.ashx?IsRefreshForm=true&ids=1759665639-1968334880-202661451-1547461133-1992083491-1000289424-159335543-1194605645-1039841082-1314140682-1793205875-131822024-232397045-468302605-1405388298-1731109441-2029667886-399776211-330369912-202888856-1376927455-1030632819-1181113682-204060739-513446117-1625018438-1460109179-1088147315-706656670-1025323794-584850082-342519603-542820515-1946640899-1603536461-1220618931-511599809-1264077421-1188909594-783705869-374257838-1463979649-1391165063-2050812538-512064351&ver=-507387479</URL> <PageURL>/main.aspx?etc=2&extraqs=%3f_gridType%3d2%26etc%3d2%26id%3d%257bA5B51CE5-3A92-E311-B0AE-6C3BE5BE5E68%257d%26rskey%3d516869557&pagemode=iframe&pagetype=entityrecord&rskey=516869557</PageURL> <Function>anonymous(gridControl){this.$Y_0=gridControl;this.$M_0=$get(this.$Y_0.get_element().id+"_titleText");this.$2o_0=$get(this.$Y_0.get_element().id+"_span")}</Function> <CallStack> <Function>anonymous(gridControl){this.$Y_0=gridControl;this.$M_0=$get(this.$Y_0.get_element().id+"_titleText");this.$2o_0=$get(this.$Y_0.get_element().id+"_span")}</Function> </CallStack> </ScriptErrorDetails> <ClientInformation> <BrowserUserAgent>Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; Zune 4.7)</BrowserUserAgent> <BrowserLanguage>en-US</BrowserLanguage> <SystemLanguage>en-IN</SystemLanguage> <UserLanguage>en-IN</UserLanguage> <ScreenResolution>1920x1080</ScreenResolution> <ClientName>Web</ClientName> <ClientTime>2014-02-21T12:34:48</ClientTime> </ClientInformation> <ServerInformation> <OrgLanguage>1033</OrgLanguage> <OrgCulture>1033</OrgCulture> <UserLanguage>1033</UserLanguage> <UserCulture>1033</UserCulture> <OrgID>{31A5A50D-DA5A-4037-A8CD-29944E2E883C}</OrgID> <UserID>{6E7D593C-38CD-449F-84F0-EBFE72CEEEDB}</UserID> <CRMVersion>6.0.1.462</CRMVersion> </ServerInformation> </CrmScriptErrorReport> <CrmScriptErrorReport> <ReportVersion>1.0</ReportVersion> <ScriptErrorDetails> <Message>Unable to get property 'get_element' of undefined or null reference</Message> <Line>1157</Line> <URL>/_common/JsProvider.ashx?IsRefreshForm=true&ids=1759665639-1968334880-202661451-1547461133-1992083491-1000289424-159335543-1194605645-1039841082-1314140682-1793205875-131822024-232397045-468302605-1405388298-1731109441-2029667886-399776211-330369912-202888856-1376927455-1030632819-1181113682-204060739-513446117-1625018438-1460109179-1088147315-706656670-1025323794-584850082-342519603-542820515-1946640899-1603536461-1220618931-511599809-1264077421-1188909594-783705869-374257838-1463979649-1391165063-2050812538-512064351&ver=-507387479</URL> <PageURL>/main.aspx?etc=2&extraqs=%3f_gridType%3d2%26etc%3d2%26id%3d%257bA5B51CE5-3A92-E311-B0AE-6C3BE5BE5E68%257d%26rskey%3d516869557&pagemode=iframe&pagetype=entityrecord&rskey=516869557</PageURL> <Function>anonymous(gridControl){this.$Y_0=gridControl;this.$M_0=$get(this.$Y_0.get_element().id+"_titleText");this.$2o_0=$get(this.$Y_0.get_element().id+"_span")}</Function> <CallStack> <Function>anonymous(gridControl){this.$Y_0=gridControl;this.$M_0=$get(this.$Y_0.get_element().id+"_titleText");this.$2o_0=$get(this.$Y_0.get_element().id+"_span")}</Function> </CallStack> </ScriptErrorDetails> <ClientInformation> <BrowserUserAgent>Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; Zune 4.7)</BrowserUserAgent> <BrowserLanguage>en-US</BrowserLanguage> <SystemLanguage>en-IN</SystemLanguage> <UserLanguage>en-IN</UserLanguage> <ScreenResolution>1920x1080</ScreenResolution> <ClientName>Web</ClientName> <ClientTime>2014-02-21T12:34:48</ClientTime> </ClientInformation> <ServerInformation> <OrgLanguage>1033</OrgLanguage> <OrgCulture>1033</OrgCulture> <UserLanguage>1033</UserLanguage> <UserCulture>1033</UserCulture> <OrgID>{31A5A50D-DA5A-4037-A8CD-29944E2E883C}</OrgID> <UserID>{6E7D593C-38CD-449F-84F0-EBFE72CEEEDB}</UserID> <CRMVersion>6.0.1.462</CRMVersion> </ServerInformation> </CrmScriptErrorReport>
Friday, February 21, 2014 7:09 AM -
It was the parallel load timing issue. This made it go away:
setTimeout( function () { formSelector(); }, 1500);
puja jain
Friday, February 21, 2014 7:19 AM -
Hi,
Sorry about that - I see what you mean.
It must be as you say something to do with the time that it takes to load scripts. I'll do some more testing.
Scott
Scott Durow
Blog www.develop1.netFollow Me
Rockstar365
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"Friday, February 21, 2014 10:07 AMAnswerer -
Thanks Scott...Friday, February 21, 2014 1:40 PM
-
Unfortunately no response. Hence I guess this is KNOWN BUG in CRM 2013.
So, only possible solution is,
function OnFormLoad() { setTimeout(function () { formSelector(); }, 1000); }
Thanks
Ajai
- Marked as answer by Ajai.CRM Thursday, February 27, 2014 6:38 AM
Thursday, February 27, 2014 6:38 AM