如何从SharePoint列表中获取超过5000项?

时间:2017-04-05 07:18:19

标签: list sharepoint records

我正在尝试从SharePoint列表中获取超过5000个项目。我使用下面的代码:

var Url = appurl +"/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + listName + "')/items?$select=ID,UserCountry,UserName/Name,UserName/Title,ModuleID/ModuleName,TopicID/TopicName,VisitCount,PolicyName,PolicyVisitCount,FAQName,FAQVisitCount,ReferenceName,ReferenceVisitCount&$top=5100&$orderby=VisitCount desc,UserName/Title asc &$expand=UserName/Title,ModuleID,TopicID&@target='" + hostWebUrl+ "'"

对于少于5000条记录,它可以正常工作。但是一旦记录数量增加(超过5000),就会产生内部服务器错误。为什么要这样做?

2 个答案:

答案 0 :(得分:0)

function fetchStatistics() {
var executor;
var appurl = appWebUrl.replace('#', '');
appurl = appWebUrl.replace('#wrapper', '');

var url = appurl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + listName + "')/items?$select=ID,UserCountry,UserName/Name,UserName/Title,ModuleID/ModuleName,TopicID/TopicName,VisitCount,PolicyName,PolicyVisitCount,FAQName,FAQVisitCount,ReferenceName,ReferenceVisitCount&$orderby=VisitCount desc,UserName/Title asc &$expand=UserName/Title,ModuleID,TopicID&@target='" + hostWebUrl + "'",
jQuery.getScript("../_layouts/15/SP.RequestExecutor.js", getStatisticsDetails);
function getStatisticsDetails()
{
    executor = new SP.RequestExecutor(appurl);
    executor.executeAsync(
        {
            url: url,
            method: "GET",
            dataType: "json",
             headers: { "Accept": "application/json; odata=verbose" },
            success: function (data) {
                var response = JSON.parse(data.body);

                if (response.d.__next) {
                    url = response.d.__next;
                    getStatisticsDetails();
                }
                bindDataGrid();
            },
            error:errorHandlerFetchStatistics
        }
    );
}

}

答案 1 :(得分:0)

检查https://msdn.microsoft.com/en-us/library/ff798465.aspx

您需要索引列表或重复调用以获得超过5000项。 您也可以在$filter来电中使用$topapi,以保持在5000以下。