A simple javascript/AJAX function to post a SOAP request to CRM 2011

This is a simple function that I use to post a SOAP envelope to CRM 2011. Just pass the URL and the xml (you can create that with this function) and you should be good to go

    function soapToCRM(URL, data) {
        var returnValue
            type: "POST",
            contentType: "text/xml; charset=utf-8",
            datatype: "xml",
            async: false,
            url: URL,
            data: data,
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
                XMLHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
                XMLHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
            success: function (data, textStatus, XmlHttpRequest) {
                var NewCRMRecordCreated = data["d"];
                returnValue = true
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("failure " + errorThrown);
                returnValue = false;
        return returnValue;


Comments are closed.

Powered by WordPress. Designed by WooThemes