微软CRM JS查询多条记录
(一) JScript
JScript一次最多返回50条数据,想要获得更多数据,需要使用__next 对象
1. 同步操作返回少于50条数据
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script src="aw_json.js" type="text/javascript"></script>
<script src="new_TestLibrary.js" type="text/javascript"></script>
<script type="text/javascript">
function clearaccountsGrid() {
var accountsGrid = document.getElementById("accountsGrid");
for (var i = accountsGrid.rows.length - 1; i >= 0; i--) {
accountsGrid.deleteRow(i);
}
}
function setElementText(element, text) {
///<summary>
/// This function mitigates the fact that IE uses innerText and other browsers use textContent.
///</summary>
if (typeof (element.innerText) != "undefined")
{ element.innerText = text; }
else
{ element.textContent = text; }
}
function Button1_onclick() {
clearaccountsGrid();
RetrieveAllAccounts()
}
function RetrieveAllAccounts() {
try {
var oDataPath = TestLibrary._ODataPath();
var filter = "/AccountSet?$select=Name";
var retrieveRecordsReq = new XMLHttpRequest();
retrieveRecordsReq.open("GET", oDataPath + filter, false);
retrieveRecordsReq.setRequestHeader("Accept", "application/json");
retrieveRecordsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveRecordsReq.send();
var retrievedResponse = JSON.parse(retrieveRecordsReq.responseText).d;
var totalAccountCount = retrievedResponse.results.length;
setElementText(document.getElementById("totalLabel"), "There are " + totalAccountCount + " accounts");
if (retrievedResponse.results.length > 0) {
var accountsGrid = document.getElementById("accountsGrid");
for (var i = 0; i < retrievedResponse.results.length; i++) {
var account = retrievedResponse.results[i];
var row = document.createElement("tr");
var nameCell = document.createElement("td");
setElementText(nameCell, account.Name);
row.appendChild(nameCell);
accountsGrid.appendChild(row);
}
}
}
catch (e) {
alert(e.Message);
}
}
</script>
<title></title>
</head>
<body>
<label id="totalLabel"></label>
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />
<div id="tableContainer">
<table id="accountsTable" rules="groups"