Read/retrieve more than 5,000 items from SharePoint using rest api:
var resultData = []; // variable (array) is used for storing list items
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Company')/items?$top=5000"; //SP list URL or REST API, In rest api Company is List name
function fetchDataFromSPList(){
$.ajax({ // Ajax
url: url,
method: "GET",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(data){
resultData = resultData.concat(data.d.results);
if (data.d.__next != undefined) {
url = data.d.__next;
fetchDataFromSPList();
}else{
console.log(resultData);
}
},
error: function(error){
// error
console.error(error);
}
});
}
fetchDataFromSPList();
Output:
Here in Company list , 8720 items are available. as shown in Image below
var resultData = []; // variable (array) is used for storing list items
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Company')/items?$top=5000"; //SP list URL or REST API, In rest api Company is List name
function fetchDataFromSPList(){
$.ajax({ // Ajax
url: url,
method: "GET",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(data){
resultData = resultData.concat(data.d.results);
if (data.d.__next != undefined) {
url = data.d.__next;
fetchDataFromSPList();
}else{
console.log(resultData);
}
},
error: function(error){
// error
console.error(error);
}
});
}
fetchDataFromSPList();
Output:
Here in Company list , 8720 items are available. as shown in Image below
Comments
Post a Comment