locked
Fech xml CRM 2011 t0 2013 RRS feed

  • Question

  • Hi,

    I was using the following code  for getting the values using fech xml nd soap

    It was working fine in 2011, but it's not supporting the 2013 beta version

    can you please suggest me on this

    function GetAttributeValue(enityName, attributeCode)
    {
        //debugger;
        var fetchxmlvalue = '<fetch mapping="logical" distinct="true" > <entity name="' + enityName + '"><attribute name="' + attributeCode + '"/></entity></fetch>';
        var fetchQuery = fetchxmlvalue;
        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>" +
        "<Fetch xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
        "<fetchXml>" + _HtmlEncode(fetchQuery) + "</fetchXml>" +
        "</Fetch>" +
        "</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/Fetch");
        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(msg);
        }

        // Process and display the results.
        else {
            // Capture the result and UnEncode it.
            var resultSet = new String();
            resultSet = resultXml.text;
            resultSet.replace('&lt;', '<');
            resultSet.replace('&gt;', '>');

            // Create an XML document that you can parse.
            var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            oXmlDoc.async = false;

            // Load the XML document that has the UnEncoded results.
            oXmlDoc.loadXML(resultSet);

            // Display the results.
            var results = oXmlDoc.getElementsByTagName('result');

            if (results.length > 0) {
                return results[0].childNodes[0].nodeTypedValue;
            }
        }
    }

    Thanks


    Rammohan

    Monday, January 20, 2014 1:06 PM

All replies

  • Hi,

    I suggest that you factor out the XMLDOM parts due to the cross browser requirements of CRM 2013 and use http://xrmsvctoolkit.codeplex.com/ or http://xrmservicetoolkit.codeplex.com/

    This will greatly simplify your code.

    Hope this helps,

    Scott


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Monday, January 20, 2014 2:59 PM
    Answerer
  • I notice your SOAP envelope points to the 2007 endpoint.  This endpoint was deprecated in CRM 2011, and is no longer available in CRM 2013.  The FetchXML has not changed, so you should be fine if you switch to the XRMServices endpoint.
    Monday, January 20, 2014 9:20 PM
  • Hi

    Can you please tell me where i have to change ....


    Rammohan

    Tuesday, January 21, 2014 5:20 AM
  • Hi Rammohan:

    I don't know if the newer endpoint supports the request you are attempting to submit, so it may not be as simple as just changing the endpoint reference.  The following is a link to the SDK metadata JavaScript for the 2011 endpoint, which is supported in 2013.  I don't know exactly what you need here, but you may be able to just include this in your solution as a web resource and make calls to its functions to get the information you want.  Then you won't have to worry about the proper SAOP formatting, etc.

    http://msdn.microsoft.com/en-us/library/gg594428.aspx

    Tuesday, January 21, 2014 2:25 PM
  • Hi Ammiti,

    Try to Use Odata Query instaed SOAP.

    Its just need to add three Libraries available in SDK.

    And directly get query using Odata  tool which is a solution import.

    Because SOAP query ma not support for Multibrowser.

    Methods like Getauthenticationheader(),getserverurl(),2007 Orgservices may not work in 2013.

    Regards

    Benarji

    Sunday, March 16, 2014 6:47 AM