locked
Xrm.Page.context.getAuthenticationHeader(); is not supported in crm 2013? RRS feed

  • Question

  • Hi,

    I am using this script in crm 2013 but  Xrm.Page.context.getAuthenticationHeader(); and selectSingleNode are not supported please tell me what should I use instead of Xrm.Page.context.getAuthenticationHeader(); and selectSingleNode

    Kindly tell me which API should I use in crm 2013

    function getEmail()
    {
        var authenticationHeader, xml, xHReq;
        var resultXml, errorCount, msg, returnValue, returnId;


        authenticationHeader = Xrm.Page.context.getAuthenticationHeader();

    var contact = Array();

         contact = Xrm.Page.getAttribute("new_predecessorid").getValue();

    //alert(contact[0].id.toString());
       alert(contact[0].name);

        // Define the SOAP XML to access Microsoft Dynamics CRM Web service.
        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>" +
        // Specify the RetrieveMultiple message.
            "<RetrieveMultiple xmlns=" +
            "\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
        // Specify that this is a QueryByAttribute query.
            "<query xmlns:q1=" +
            "\"http://schemas.microsoft.com/crm/2006/Query\" " +
            "xsi:type=\"q1:QueryByAttribute\">" +
        // Query the customeraddress entity.
            "<q1:EntityName>contact</q1:EntityName>" +
        // Set the columns you want to return.
            "<q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
            "<q1:Attributes>" +
            "<q1:Attribute>emailaddress1</q1:Attribute>" +

            "</q1:Attributes>" +
            "</q1:ColumnSet>" +
        // Specify the attribute that you are querying on.
            "<q1:Attributes>" +
            "<q1:Attribute>contactid</q1:Attribute>" +
            "</q1:Attributes>" +
        // Set the value of the attribute using the customerid
        // value of the case record.
            "<q1:Values>" +
            "<q1:Value xsi:type=\"xsd:string\">" +
            contact[0].id +
            "</q1:Value>" +
            "</q1:Values>" +
            "</query>" +
            "</RetrieveMultiple>" +
            "</soap:Body>" +
            "</soap:Envelope>";

        // Create an instance of an XMLHTTP object.
        xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        // Configure the XMLHttp object for the Microsoft CRM Web services.
        xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
        xmlHttpRequest.setRequestHeader(
            "SOAPAction",
            "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple"
            );
        xmlHttpRequest.setRequestHeader(
            "Content-Type", "text/xml; charset=utf-8"
            );
        xmlHttpRequest.setRequestHeader(
            "Content-Length", xml.length
            );
        // Send the XMLHttp request.
        xmlHttpRequest.send(xml);
        // Capture the XMLHttp response in XML format.
        resultXml = xmlHttpRequest.responseXML;

        errorCount = resultXml.selectNodes('//error').length;
        // alert(errorCount.toString());
     if (errorCount != 0) {

            msg = resultXml.selectSingleNode('//description').nodeTypedValue;

            alert("An error has been occured on loading Customer Information\nError Details: " + msg);

        }

        else {

            if (resultXml.selectNodes("//q1:emailaddress1") != null) {




                var req = resultXml.selectSingleNode("//q1:emailaddress1").nodeTypedValue;
                Xrm.Page.getAttribute("new_emailaddress").setValue(req);
            }

            else {

                alert("CRM 2011 encountered an error while fetching for email address");

            }

        }
    }

    Thursday, March 20, 2014 11:58 AM

All replies

  • It is recommended all SOAP calls to be replaced by oData.

    Who have and example of how to do it here.

    Thursday, March 20, 2014 12:15 PM