Dec 07 2022 11:26 PM
I have a List in a SharePoint Online site collection which has exceeded 5000 items. I have indexed the columns that are needed in the REST API filter query during list creation itself.
Below is the Rest API query I use to fetch the data from the list.
https://sptenant.sharepoint.com/sites/spfxqaw44/_api/web/lists/getByTitle('Announcements')/items?$top=4999
&$filter=(Expires ge '2022-12-06T18:30:00.000Z') and (RecordDate le '2022-12-06T18:30:00.000Z') and IsActive eq 1 and WorkflowCompleted eq 1
&$select=Id,Title,Expires,ShortDescription,Created,RecordDate,Attachments,LangTrans&$expand=AttachmentFiles&$orderby=RecordDate desc
The above query gave me an error as threshold limit exceeded. So I have created a simple list and made a API call as below,
https://sptenant.sharepoint.com/sites/testsite/_api/web/lists/getByTitle('LoadTestList')/items?$filt... ne 'Load Test'&$top=4999
Generally the return data count should be 4999 but I am able to get only 4970 items as response data. Also this response count is unpredictable, for some other lists I got response count less than 4000.
Any idea on this inconsistent behavior?
Dec 08 2022 02:40 PM
You need to use Pagingation to get more items that 5000. Here is a JS snippet that should do it for you
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Announcements')/items?$top=5000";
var response = response || []; // this variable is used for storing list items
function GetListItems(){
return $.ajax({
url: url,
method: "GET",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(data){
response = response.concat(data.d.results);
if (data.d.__next) {
url = data.d.__next;
GetListItems();
}
$.each(response, function(index, item) {
arrayListItem[index] = item;
});
},
error: function(error){
}
});
}
Dec 10 2022 05:55 AM