locked
Unable to get property 'length' of undefined or null reference on CRM 2011 form on IE11 RRS feed

  • Question

  • I have and onchange function set up on a field on my Lead CRM 2011 form. Everything works correctly on IE9, but after upgrading to IE11 I get an onchange event error. 

    Unable to get property 'length' of undefined or null reference

    Here is my code:

    function leadsourcecode_onchange() {
        //LeadSourceCode OnChange --winner
        //"Right" function
        function Right(str, n) {
            if (n <= 0)
                return "";
            else if (n > String(str).length)
                return str;
            else {
                var iLen = String(str).length;
                return String(str).substring(iLen, iLen - n);
            }
        }

        var oLeadsourcecode = crmForm.all.leadsourcecode;
        var oSecondaryLeadsourcecode = crmForm.all.new_secondaryleadsource;
        var oFilter = null;
        var currentselectedvalue = oSecondaryLeadsourcecode.DataValue;

        oSecondaryLeadsourcecode.Disabled = false;


        // Get Sub-Category Filter
        oFilter = Right(oLeadsourcecode.SelectedText, 2);



        var iIndex = 0;
        var text1 = null;

        // Set the picklist back to the original value
        oSecondaryLeadsourcecode.Options = oSecondaryLeadsourcecode.originalPicklistOptions;

        // Create a new array, which will hold the new picklist options
        var oTempArray = new Array();

        // Initialize the index for the temp array
        var iIndex = 0;
        var iNewIndex = 0;


        for (var i = 0; i < oSecondaryLeadsourcecode.originalPicklistOptions.length; i++) {

            oSecondaryLeadsourcecode.DataValue = i;
            text1 = oSecondaryLeadsourcecode.children[i].innerHTML;

            if (i == 0) {
                oSecondaryLeadsourcecode.DataValue = 0;

                // Found the required field
                oSecondaryLeadsourcecode.AddOption(text1, 0);
                iNewIndex = oSecondaryLeadsourcecode.selectedIndex;
                oTempArray[iIndex] = oSecondaryLeadsourcecode.originalPicklistOptions[0];
                iIndex++;
            }

            // Search for filter in text1    
            if (text1.indexOf(oFilter) != -1) {
                oSecondaryLeadsourcecode.DataValue = i;

                // Found the required field
                oSecondaryLeadsourcecode.AddOption(text1, i);
                iNewIndex = oSecondaryLeadsourcecode.children[i].index;
                oTempArray[iIndex] = oSecondaryLeadsourcecode.originalPicklistOptions[iNewIndex];
                iIndex++;

            }
        }
        // Reset the Sub-Industry picklist with the new options
        oSecondaryLeadsourcecode.Options = oTempArray;
    }
    function mobilephone_onchange() {
        // Attempt to auto-format basic US phone numbers.  This method supports
        // 7 and 10 digit numbers.  Example: (410) 555-1212

        // Get the field that fired the event
        var oField = Xrm.Page.getAttribute("mobilephone");
        //var oField = event.srcElement;

        // If we have the field and all is well
        if (typeof (oField) != "undefined" && oField != null) {
            // Remove any non-numeric characters
            var sTmp = oField.getValue().replace(/[^0-9]/g, "");

            // If the number is a length we expect and support, format the number
            switch (sTmp.length) {
                case "4105551212".length:
                    oField.setValue("(" + sTmp.substr(0, 3) + ") " + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4));
                    break;

                case "5551212".length:
                    oField.setValue(sTmp.substr(0, 3) + "-" + sTmp.substr(3, 4));
                    break;
            }
        }
    }

    When I turn on debugging in IE11 it shows a DOM7011 error. "The code on this page disabled back and forward caching. For more information, see: http://go.microsoft.com/fwlink/?LinkID=291337"

    Thanks for any assistance,

    -Brian

    Wednesday, July 1, 2015 4:28 PM

All replies

  • your code is using unsupported customization, for this it's not working.

    In addition it uses CRM 4.0 JavaScript style.


    My blog: www.crmanswers.net - CRM Theme Generator

    Wednesday, July 1, 2015 4:33 PM
  • Can you explain why the customization is unsupported?

    I updated the JavaScript style to CRM 2011 in my test environment and I am getting the same results, except now it doesn't work in IE9 or IE11...

    Wednesday, July 1, 2015 4:37 PM
  • just an example

    this is still CRM 4.0

        var oLeadsourcecode = crmForm.all.leadsourcecode;
        var oSecondaryLeadsourcecode = crmForm.all.new_secondaryleadsource;
        var oFilter = null;
        var currentselectedvalue = oSecondaryLeadsourcecode.DataValue;

        oSecondaryLeadsourcecode.Disabled = false;

    this is unsupported

     text1 = oSecondaryLeadsourcecode.children[i].innerHTML;

        iNewIndex = oSecondaryLeadsourcecode.children[i].index;


    My blog: www.crmanswers.net - CRM Theme Generator

    Wednesday, July 1, 2015 5:09 PM