We have a list with 0.5 Million items.
The end goal is to get and handle threshold using recursive function. Followed the below article however didn't work as per our requirement. Rest to read more than 5000 items from document library
Code
function FilteredInvoiceNew(ColumnName,ColumnVal){
var dataset = [];
var FltrInv = [];
var response = response || [];
var ApprovalStatus = "";
var listName="Claimlist";
var myQuery= _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ListName')/items?$select=ID,P_x0020_No,Inv_x0020_Date,Item_x0020_No,ProductCode,Qty,Prj_x0020_Name,
Distributor_x0020_No,Distributor_x0020_Name,Contractor_x0020_Name,Claim_x0020_Amount,YourReference,YourProductCode,YourPONumber,IsApproved,Comments";
if(ColumnName!=="" && ColumnVal!==""){
myQuery+="&$filter=substringof('"+ColumnName+"',"+ColumnVal+")";
}
myQuery+="&$top=500";
myQuery+="&$orderby=ID desc";
debugger;
return $.ajax({
url: myQuery,
method: "GET",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(data){
response = response.concat(data.d.results);
if (data.d.__next) {
myQuery = data.d.__next;
FilteredInvoiceNew();
}
const lookup = response.reduce((a, e) => {
a[e.YourReference] = ++a[e.YourReference] || 0;
return a;
}, {});
FltrInv = response.filter(e => lookup[e.YourReference]);
console.log(FltrInv);
$.each(FltrInv, function(index, row) {
// SomeCode
});
},
error: function(error){
console.log(error);
}
});// End of Ajax Call
}
Executing the function goes to the error section and throws the threshold error as shown below
Also tried nested function to include the below logic and it skips the nested function.
Would be extremely grateful if anyone could let us know if this is achievable.
Thanks in advance