locked
Converting 2007 endpoints for CRM 2013 RRS feed

  • Question

  • Can anyone tell me how to convert this code so it no longer uses 2007 endpoints please?

    function SetDG(salesorderdetailid, nDG) {
        var result = false;
        var entityName = "SalesOrderDetail";
        var entityIdFieldName = entityName.toLowerCase() + "id";
        try {
            if (salesorderdetailid != null) {
                var resultArray = new Array();
                var attributesList = '<' + entityIdFieldName + '>' + salesorderdetailid + '</' + entityIdFieldName + '>';
                attributesList += "<btl_deliverygroup>" + nDG + "</btl_deliverygroup>";
                var xml = "<Update xmlns='http://schemas.microsoft.com/crm/2007/WebServices'><entity xsi:type='"
                        + entityName + "'>" + attributesList + "</entity></Update>";
                result = CallCrmService(xml, 'Update');
                result = true;
            }
        }
        catch (err) { result = false; }

        return result;
    }

    function CallCrmService(soapBody, method) {
        var success = false;
        try {
            var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            xmlHttpRequest.Open("POST", '/mscrmservices/2007/CrmService.asmx', false); //synchronous
            xmlHttpRequest.setRequestHeader("SOAPAction", 'http://schemas.microsoft.com/crm/2007/WebServices/' + method);
            xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            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\'>" +
    Xrm.Page.context.getAuthenticationHeader() + "<soap:Body>" + soapBody + "</soap:Body></soap:Envelope>";
            xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
            xmlHttpRequest.send(xml);

            var resultXml = xmlHttpRequest.responseXML;
            var errorCount = resultXml.selectNodes('//error').length;

            if (errorCount != 0) {
                var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
                alert(msg);
                success = false;
            }
            else
            { success = true; }
        }
        catch (err) {
        }

        return success;
    }

    Wednesday, July 16, 2014 8:57 AM

All replies

  • Hi,

    The 2007 endpoint used SOAP calls for making Update requests (as can be guessed from your code). The 2011 endpoint introduced the REST api, also known as the OData, where you can make update requests using REST Calls.

    Have a look here to see how you can make an Update request. You'll need to rewrite your code using the REST call.


    Admin QuikView Solution for CRM 2013

    Wednesday, July 16, 2014 9:27 AM
  • Or if you want to use soap call only you can write you server side request in Soaplogger utility and it will convert it to client side soap request call that you can replace with your code.

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


    Our Website| Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Wednesday, July 16, 2014 10:16 AM
    Moderator