locked
MS CRM 2011 ONLINE - Mozilla Firefox 25.0 + Use of document.createAttribute() is deprecated. RRS feed

  • Question

  • I am using the code below to set a field based on lookup record. This works well using Internet Explorer 10.0.9200.16721.

    Now using Firefox 25.0 I am getting this error message:

    There was an error with this field's customized event.
    Field:customerid
    Event:onchange
    Error:undefined

    Also when using Firefox's debugger I get this:

    Use of document.createAttribute() is deprecated. Use element.setAttribute() instead.

    How can I resolve this issue?

    function GetPay() {
    
        var EntityName, EntityId, LookupFieldObject, payment;
        var PrimaryContactLookupId, PrimaryContactLookupName, PrimaryContactLookupType;
        var resultXml;
    
    
    
        LookupFieldObject = Xrm.Page.data.entity.attributes.get('customerid'); 
    	
        // If lookup field has value then the code will only run
        if (LookupFieldObject.getValue() !== null) {
    
    
    	
        
    	
    
            //Fetch and place Entity Id (GUID) and Name (String) form lookup field into local variables
            EntityId = LookupFieldObject.getValue()[0].id;
            EntityName = LookupFieldObject.getValue()[0].entityType;
    
            // Paramter explaination for function call
            // RetrieveEntityById('account', AccountId, 'accountnumber,emailaddress1');
    
            // 1st paramter requires entity name (not display or schema name) just pass it in a string
            // i.e. for Account entity use 'account' for opportunity entity use 'opportunity'
    
            // 2nd paramter requires entity Id (GUID Type) field which we have retrieved and stored in
            // AccountId local variable
    
            // 3rd paramter requires attributes to be retrieved schema name, if thrid attributed is
            // required to be retrieved then use like: i.e. 'accountnumber,emailaddress1,telephon
    
            resultXml = RetrieveEntityById(EntityName, EntityId, 'new_payment');
    		
    
            // In retrieved XML document check if it has accountnumber attribute
            if (resultXml !== null && resultXml.selectSingleNode('//q1:new_payment') !== null) {
    
                payment = resultXml.selectSingleNode('//q1:new_payment').nodeTypedValue;
    
    			//Display Account Number Value in a Message Box
                
    
    
    			Xrm.Page.data.entity.attributes.get('new_payment').setValue(payment);
    Xrm.Page.getAttribute('new_payment').fireOnChange();
    
                //If required then use the below code line to set value in field on form
                //Xrm.Page.data.entity.attributes.get('new_myaccountnumber').setValue(AccountNumber);
            }
    		
    	            
    			
               
            }      
    
        
    
    
    // Do not make any changes to this function
    function RetrieveEntityById(prmEntityName, prmEntityId, prmEntityColumns) {
    
        var resultXml, errorCount, msg, xmlHttpRequest, arrayEntityColumns, xmlEntityColumns;
    
        arrayEntityColumns = prmEntityColumns.split(",");
    
        for (var i = 0; i < arrayEntityColumns.length; i++) {
            xmlEntityColumns += "<q1:Attribute>" + arrayEntityColumns[i] + "</q1:Attribute>";
        }
    
        var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();
    
        //Prepare the SOAP message.
        var xml = "<?xml version='1.0' encoding='utf-8'?>" +
        "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
        " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
        " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
        authenticationHeader +
        "<soap:Body>" +
        "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
        "<entityName>" + prmEntityName + "</entityName>" +
        "<id>" + prmEntityId + "</id>" +
        "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +
        "<q1:Attributes>" +
        xmlEntityColumns +
       "</q1:Attributes>" +
        "</columnSet>" +
        "</Retrieve></soap:Body></soap:Envelope>";
    
        //call function to create Soap Request to ms crm webservice
        xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
        xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
        xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
        xmlHttpRequest.send(xml);
    
        resultXml = xmlHttpRequest.responseXML;
    
        var errorCount = resultXml.selectNodes('//error').length;
    
        if (errorCount !== 0) {
            var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
            alert("Error Message : " + msg);
        }
        else {
            return resultXml;
        }
    }
    
    }



    Monday, November 18, 2013 6:51 AM

All replies

  • Hi,
    the problem in your code is that you are using the ActiveX for your webservice calls and the CRM 4.0 endpoints.
    When your CRM Online instance will be migrated to CRM 2013 the CRM 4.0 endpoint will not be available anymore, and ActiveX can be used only with Internet Explorer.

    You need to rewrite your code using a javascript library like XrmServiceToolkit (http://xrmservicetoolkit.codeplex.com/


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Monday, November 18, 2013 7:43 AM
  • Hi and thanks

    But basically what should I do? I have no idea what to do next. Can you define where I am using ActiveX?

    Monday, November 18, 2013 7:59 AM
  • Ok, so I run Custom Code Validation Tool and got this for example: The occurrence of .selectSingleNode was located 5 time(s) in this web resource.

    So how I replace that .selectSingleNode and shoud I do something more?

    Monday, November 18, 2013 8:38 AM