//create the fetch
var bodyFetch = '--batch_recordfetch\n'
bodyFetch += 'Content-Type: application/http\n'
bodyFetch += 'Content-Transfer-Encoding: binary\n'
bodyFetch += '\n'
bodyFetch += 'GET ' + crmurl + entitySetName + '?fetchXml=' + fetchxml + ' HTTP/1.1\n'
bodyFetch += 'Content-Type: application/json\n'
bodyFetch += 'OData-Version: 4.0\n'
bodyFetch += 'OData-MaxVersion: 4.0\n'
bodyFetch += 'Prefer: odata.include-annotations=*\n'
bodyFetch += 'Access-Control-Allow-Origin: *\n'
bodyFetch += '\n'
bodyFetch += '--batch_recordfetch--'
//create ajax request
var jqxhr = $.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
datatype: "json",
async: false,
url: crmurl + "$batch",
data: bodyFetch,
beforeSend: function (xhr) {
//Specifying this header ensures that the results will be returned as JSON.
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("OData-MaxVersion", "4.0");
xhr.setRequestHeader("OData-Version", "4.0");
xhr.setRequestHeader("Access-Control-Allow-Origin", "*")
xhr.setRequestHeader("Prefer", "odata.include-annotations=*");
xhr.setRequestHeader("Content-Type", "multipart/mixed;boundary=batch_recordfetch");
}
});
var response = { valid: jqxhr.statusText, data: jqxhr.responseText };