I am facing the challenge of exceeding the 5000 view limit in SharePoint Online and need to implement recursive RestAPI calls to overcome this limitation. The code I have currently goes into a loop after generating the initial 5000 entries from my SharePoint list, which contains a total of only 8800 entries.
My goal is to fetch the first batch of 5000 entries followed by the remaining 3800 entries using recursive calls and then display the combined data in Jquery Datatables.
$(document).ready(function() {
var table = $('#table_id').DataTable({
"pageLength": 100,
"dom": 'Bfrtip',
"buttons": [searchBuilder, copy],
"aoColumns": [{"mData": "Created"}, {"mData": "EncodedAbsUrl"}]
});
var response = response || [];
var listURL = "SPO_Site/_api/web/lists/getbytitle('List_Name')/items?$top=5000&$select=Created,EncodedAbsUrl";
GetListItemsRecursive(listURL);
function GetListItemsRecursive() {
$.ajax({
url: listURL,
type: "GET",
dataType: "json",
headers: {
"accept": "application/json;odata=verbose"
},
success: mySuccHandler,
error: myErrHandler
});
}
function mySuccHandler(data) {
response = response.concat(data.d.results);
console.log(data);
if (data.d.__next) {GetListItemsRecursive(data.d.__next);}
try {table.rows.add(response).draw();}
catch (e) {alert(e.message);}
}
function myErrHandler(data, errMessage) {alert("Error");}
});