ActiveXObject not supporting Other than IE browser. RRS feed

  • Question

  • In my project i have used below mentioned code to retrieve fields.Its working fine in IE but when i use with Firefox and chrome its getting error since ActiveXObject doesnot support other browser.I find the solution, Where they are saying to use odata query.But my project i have used lot of places below code..can any one suggest me for solution.

    Thanx in advance..

    My code is

    function RetrieveEntityVaules(prmEntityName, prmEntityId, prmEntityColumns) {

    var returnvalue, errorCount, msg, xmlHttp, 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>" +

    //call function to create Soap Request to ms crm webservice
    xmlHttp= new ActiveXObject("Msxml2.XMLHTTP");




    xmlHttp.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);

    xmlHttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");

    xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

    xmlHttp.setRequestHeader("Content-Length", xml.length);


    returnvalue= xmlHttp.responseXML;

    var errorCount = returnvalue.selectNodes('//error').length;

    if (errorCount != 0) {
    var msg = returnvalue.selectSingleNode('//description').nodeTypedValue;
    alert("Error Message : " + msg);
    else {

    return returnvalue;

    Arun Kumar G

    Friday, August 23, 2013 12:45 PM

All replies

  • Hi

    I somewhere read that on all latest browsers, ActiveXObject is not supported. Instead you need to use XMLHttpRequest. 

    Rough example goes like this

     var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();
            if (idVal != null && idVal != "undefined") {
      var oDataPath = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/organizationdata.svc";
    var filter = "/<EntitySetName>?" +
      "$select=<FieldNames>" +
      "&$filter=<Filtercriteria>" +
      "&$top=1"; // <Optional>
    var retrieveRecordsReq = new XMLHttpRequest();
    retrieveRecordsReq.open("GET", oDataPath + filter, false);
    retrieveRecordsReq.setRequestHeader("Accept", "application/json");
    retrieveRecordsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    if (retrieveRecordsReq.status == 200) {
        var retrievedRecords = JSON.parse(retrieveRecordsReq.responseText).d;

    Friday, August 23, 2013 1:13 PM
  • I would suggest using jQuery (http://jquery.com/), specifically http://api.jquery.com/jQuery.ajax/ to do the request. jQuery handles the cross browser compatability issues for you.

    Michael Palmer
    xRMPalmer     @MJFPalmer     Rockstar365

    • Proposed as answer by MJFPalmer Saturday, August 24, 2013 8:10 PM
    Saturday, August 24, 2013 8:10 PM
  • Dear friend,

                      Thanks for your interest on my question.But i used the above code also(XMLHttpRequest).But its not working. Can u give me the another solution.

                            Thanx in advance

    Arun Kumar G

    Wednesday, August 28, 2013 5:40 AM
  • Dear Michael,

     Thanks for your interest on my question.If u elobarate your answer, it will be useful for me.Pls can u elobarate your answer?

     Thanx in advance

    Arun Kumar G

    Wednesday, August 28, 2013 5:42 AM
  • Hi Arun,

    The XMLHttpRequest posted code above should have worked. If you are still having issues with this, maybe look into using the XrmSvcToolkit (https://xrmsvctoolkit.codeplex.com) to do the retrieve. This library handles the XMLHttpRequest for you and is cross browser compatible.

    Michael Palmer
    xRMPalmer     @MJFPalmer     Rockstar365

    Wednesday, August 28, 2013 10:25 AM
  • Dear Michael Palmer,

             I used XrmSvcToolkit (https://xrmsvctoolkit.codeplex.com) also.But its not working.

    Arun Kumar G

    • Edited by Aronkumar Thursday, August 29, 2013 10:19 AM
    Thursday, August 29, 2013 10:18 AM