sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

Recursive function to handle list view threshold not working

Open vivekmurli opened this issue 5 years ago • 3 comments

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

image

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

vivekmurli avatar Jun 10 '21 17:06 vivekmurli

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

ghost avatar Jun 10 '21 17:06 ghost

If you want to filter more than 5k items in SharePoint list, you need to create index for that column in list settings

image

Michael Han Microsoft SharePoint Community Support

michaelhan-1 avatar Jun 14 '21 06:06 michaelhan-1

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

ghost avatar Jun 18 '21 13:06 ghost