locked
Activexobject is undefined, I am getting this error for cross browser issue after I did Rollup 14. RRS feed

  • Question

  • Hi All,

    Activexobject is undefined, I am getting this error for cross browser issue after I did Rollup 14.

    Please let me know if you can change this code to make it compatible for the crossbowser

    //HCC Code for dynamic lookups based on market code selected
    function SBSPOC_Update() {
        var marketcodeid;

        // Get the parent account name from a lookup field.
        var ar = new Array();
        if (Xrm.Page.getAttribute("ascent_mktcodeid").getValue() != null) {
            ar = Xrm.Page.getAttribute("ascent_mktcodeid").getValue();
            marketcodeid = ar[0].id;

            //read the SBS POC
            var sbspoc;
            var sbspocname;

            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>ascent_mktcode</entityName>" +
        "<id>" + marketcodeid + "</id>" +
        "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +
        "<q1:Attributes>" +
        "<q1:Attribute>hcc_sbspocid</q1:Attribute>" +
        "</q1:Attributes>" +
        "</columnSet>" +
        "</Retrieve>" +
        "</soap:Body>" +
        "</soap:Envelope>";
            // Prepare the xmlHttpObject and send the request.
            var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
            xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
            xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
            xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            xHReq.setRequestHeader("Content-Length", xml.length);
            xHReq.send(xml);
            // Capture the result.
            var resultXml = xHReq.responseXML;
            // Check for errors.
            var errorCount = resultXml.selectNodes('//error').length;
            if (errorCount != 0) {
                var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
                //alert('error occured');
            }
            else {
                // read the sbs poc

                if (resultXml.selectSingleNode("//q1:hcc_sbspocid") != null && resultXml.selectSingleNode("//q1:hcc_sbspocid").nodeTypedValue != null) {
                    sbspoc = resultXml.selectSingleNode("//q1:hcc_sbspocid").nodeTypedValue;
                    sbspocname = resultXml.selectSingleNode("//q1:hcc_sbspocid").getAttribute("name");

                }
            }

    Friday, November 1, 2013 9:35 PM

All replies

  • Replace this:
    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");

    By this:
    var xHReq = new XMLHttpRequest();

    Or you can use OData, see this article:

    http://www.powerobjects.com/blog/2012/10/29/cross-browser-for-activexobject/

    Saturday, November 2, 2013 1:58 AM
  • that did not work, I am not very familiar with odata services, sorry but can anyone recode this for me!!!
    • Edited by Nandhini12 Saturday, November 2, 2013 6:56 PM
    Saturday, November 2, 2013 3:46 PM
  • I believe that the code below could help you, I tried change to your data.

    Example:

    function ExecuteCode() {
        var marketcodeid = Xrm.Page.data.entity.attributes.get("ascent_mktcodeid");
        if (marketcodeid.getValue() != null) {
            theId = marketcodeid.getValue()[0].id;
            getEntityByID("Contact", "ContactId", theId, "hcc_sbspocid");
        }
    }

    function getEntityByID(theEntity, theIdFieldName, theId, theFields) {

        var pagecontext = Xrm.Page.context;
        var serverUrl = pagecontext.getServerUrl();
        var oDataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
        var oDataSelect = oDataPath + "/" + theEntity + "Set?$select=" + theFields + "&amp;$filter=" + theIdFieldName + " eq guid’" + theId + "’";
        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: oDataSelect,

            beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },

            success: function (data, textStatus, XmlHttpRequest) {
                var theEntityFields = data.d.results;
                sbspocname = theEntityFields[0].hcc_sbspocid;
            },

            error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
        });
    }

    See this article.

    http://www.powerobjects.com/blog/2012/10/29/cross-browser-for-activexobject/ 


    Jose Andre Filho - Consultor Dynamics CRM


    Saturday, November 2, 2013 11:32 PM
  • I am getting a syntax error in this, can anyone let me know, I want fresh eyes to take a look , I am missing something.

    function getEntityByID(theEntity, theIdFieldName, theId, theFields) {

       

    var pagecontext = Xrm.Page.context;

        

    var serverUrl = pagecontext.getServerUrl();

        

    var oDataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";

        

    var oDataSelect = oDataPath + "/" + theEntity + "Set?$select=" + theFields + "&amp;$filter=" + theIdFieldName + " eq guid" + theId + "";

         $.ajax({

             type:

    "GET",

             contentType:

    "application/json; charset=utf-8",

             datatype:

    "json",

             url: oDataSelect,

             beforeSend:

    function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },

             success:

    function (data, textStatus, XmlHttpRequest) {

                

    var theEntityFields = (data.d.results);

                 sbspocname = theEntityFields[0].hcc_sbspocid;

             },

             error:

    function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }

         });

    }

    Thursday, November 7, 2013 6:06 PM
  • You have to add libraries Json and Jquery as WebResource and add to the form.


    Jose Andre Filho - Consultor Dynamics CRM

    Thursday, November 7, 2013 6:34 PM