我在异步调用“SDK.REST.retrieveMultipleRecords”函数时遇到一些问题。下面是我的问题的代码
function Main_Method(_AnimalList)
{
new SearchInAnimalRecords(_AnimalList);
}
function SearchInAnimalRecords(_AnimalList)
{
$('#divProgressDetail').append('<br>Start searching Animal Records...');
for (var i = 0; i < _AnimalList.length; i++)
if (_AnimalList[i].SchemaName != "Lion")
this.Process(AnimalSchemaName);
}
SearchInAnimalRecords.prototype.Process = function (AnimalSchemaName)
{
$('#divProgressDetail').append('<br>Retriving ' + AnimalSchemaName + ' Animal Records...');
///SDK.REST.retrieveMultipleRecords : Sends an asynchronous request to retrieve records.
SDK.REST.retrieveMultipleRecords
(
AnimalSchemaName, /// The Schema Name of the Entity type record to retrieve.
"$select=" + AnimalSchemaName + "Id", /// A String representing the OData System Query Options to control the data returned
function (AnimalRecords) // "AnimalRecords" only contain 50 records
此函数将被传递并为返回的每页记录调用。 每页有 50 条记录。如果您预计将返回一页以上的记录, 该函数应该循环遍历结果并将记录推送到函数外部的数组中。 使用 OnComplete 事件处理程序了解所有记录何时已处理完毕。
{
var length = AnimalRecords.length;
for (var i = 0; i < length; i++)
{
var guid = AnimalRecords[i][AnimalSchemaName + 'Id'];
var IsGuidMatch = IsKeyGuidMatchWith(guid);
if (IsGuidMatch)
{
$('#divProgressDetail').append('<br>Key animal found in ' + AnimalSchemaName + ' Records.');
$('#divProgressDetail').append('<br>Searching stop.');
break;
}
}
},
function () /// The function that will be passed through and be called by a failed response.
{
$('#divProgressDetail').append('<br>Error while Retriving ' + AnimalSchemaName + ' Records.');
},
function () /// OnComplete EventHandler The function that will be called when all the requested records have been returned. No parameters are passed to this function.
{
$('#divProgressDetail').append('<br>Completed searching in ' + AnimalSchemaName + ' Records.');
}
);
}
在Process函数中,它们是一个匿名函数,它接受一个名为“AnimalRecords”的参数。所以问题是这个 AnimalRecords 仅包含 50 条记录,我一次需要所有记录。
最佳答案
我认为这是对返回记录数量的限制。每次检索记录时,仅返回查询中的前 50 条记录。如果记录超过 50 条,则结果集末尾会出现 XML 中的“>”节点或 JSON__next 属性。您可以使用该节点或属性中的 URL 值继续处理下一组记录。 URL 包含一个 $skiptoken 参数,该参数提供有关分页边界的信息
引用:http://msdn.microsoft.com/en-us/library/gg334767.aspx
如果您想访问所有记录,请尝试使用 xrmservicetoolkit
XrmServiceToolkit.Soap.QueryAll:返回所有记录 (>5k+) 的方法。
关于javascript - MSCRM async javascript SDK.REST.retrieveMultipleRecords 仅返回 50 条记录,一次需要所有记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20540921/