Hi Andrew, thanks for your reply. The requests are called from a separate JavaScript file (below) and the data is displayed in the HTML web resource.
The call to this JavaScript file looks like this and it is called from a second JavaScript file on load of the form (initiated by $( document).ready()
SDK.RestEndpointPaging.RetrieveRecords("/cs_mainactivitySet?$select=cs_mainactivityId,cs_name,cs_IsInScope,cs_Description", mainActivityDataCallback);
Here is the code for the JavaScript that makes the HTTPRequest. When I debug through the readyState is 'undefined' :
if (typeof (SDK) == "undefined")
{ SDK = { __namespace: true }; }
// Namespace container for functions in this library.
SDK.RestEndpointPaging = {
GetODataPath: function () {
/// <summary>
/// Utility function to retrieve the path to the REST endpoint.
/// </summary>
var restEndPoint = "/" + Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc";
return restEndPoint;
},
RetrieveRecords: function (filter, callback) {
/// <summary>
/// Initiates an asynchronous request to retrieve records.
/// If there are additional pages of records the SDK.RestEndpointPaging.RetrieveRecordsCallBack function will
/// call this function.
/// </summary>
var retrieveRecordsReq = new XMLHttpRequest();
retrieveRecordsReq.open("GET", SDK.RestEndpointPaging.GetODataPath() + filter, true);
retrieveRecordsReq.setRequestHeader("Accept", "application/json");
retrieveRecordsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveRecordsReq.onreadystatechange = function () {
/// <summary>
/// This event handler passes the callback through
/// </summary>
SDK.RestEndpointPaging.RetrieveRecordsCallBack(this, callback);
};
retrieveRecordsReq.send();
},
RetrieveRecordsCallBack: function (retrieveRecordsReq, callback) {
/// <summary>
/// Handles the onreadystatechange event to process the records returned.
/// If more pages are available this function will call the SDK.RestEndpointPaging.RetrieveRecords
/// function to get the rest.
/// </summary>
if (retrieveRecordsReq.readyState == 4 /* complete */) {
if (retrieveRecordsReq.status == 200) {
var retrievedRecords = JSON.parse(retrieveRecordsReq.responseText).d;
/// The callback is called with the results.
callback(retrievedRecords.results);
if (null != retrievedRecords.__next) {
// The existance of the '__next' property indicates that more records are available
// So the originating function is called again using the filter value returned
//var filter = retrievedRecords.__next.replace(SDK.RestEndpointPaging.GetODataPath(), "");
var filter = retrievedRecords.__next.substr(retrievedRecords.__next.indexOf(".svc/")+4 , retrievedRecords.__next.length);
SDK.RestEndpointPaging.RetrieveRecords(filter, callback);
}
}
else {
//Failure
SDK.RestEndpointPaging.errorHandler(retrieveRecordsReq);
}
}
},
//Function to handle any http errors
errorHandler: function (XmlHttpRequest) {
/// <summary>
/// Simply displays an alert message with details about any errors.
/// </summary>
alert("Error : " +
XmlHttpRequest.status + ": " +
XmlHttpRequest.statusText + ": " +
JSON.parse(XmlHttpRequest.responseText).error.message.value);
},
__namespace: true
};