Recursive function to handle list view threshold not working
What type of issue is this?
other
What SharePoint development model, framework, SDK or API is this about?
SharePoint REST API
Target SharePoint environment
SharePoint Online
What browser(s) / client(s) have you tested
- [ ] 💥 Internet Explorer
- [ ] 💥 Microsoft Edge
- [X] 💥 Google Chrome
- [ ] 💥 FireFox
- [ ] 💥 Safari
- [ ] mobile (iOS/iPadOS)
- [ ] mobile (Android)
- [ ] not applicable
- [ ] other (enter in the "Additional environment details" area below)
Additional environment details
No response
Issue description
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.
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
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
If you want to filter more than 5k items in SharePoint list, you need to create index for that column in list settings

Michael Han Microsoft SharePoint Community Support
Closing this issue as "answered". If you encounter a similar issue(s), please open up a new issue. See our wiki for more details: Issue-List: Our approach to closed issues