This is a topic discussed many times before but I have a peculiar case now and need some expert opinion on this.Below is a sample scenario I am trying to test:

My List Set up:

  1. List has 10k items.
  2. 10k items is divided into 10 year folders (2010 to 2020) with below structure.
 => Root Folder 
       => 2010 Folder (4 Folders)
           => Q1 Folder (250 items)
               => item 1
               => item 2
               => item 250
           => Q2 Folder (250 items)
           => Q3 Folder (250 items)
           => Q4 Folder (250 items)
         => 2011 Folder (4 Folders)
  • Each year folder has 4 sub folders (Q1, Q2, Q3, Q4) one for each quarter. Each quarter sub folder has 250 items. So in total each year folder will have 1000 items. There is no possibility for any particular folder to have more than 5000 items.

Now, I am trying to use CAML Query in JSOM to get all items for a particular year by using the set_folderServerRelativeUrl option in CamlQuery. Below is my caml query:

var camlQuery = `<View Scope='RecursiveAll'>             
         <Query><Where><BeginsWith><FieldRef Name='ContentTypeId'/><Value Type='ContentTypeId'>${contentypid_sample}</Value></BeginsWith></Where></Query>
                 <OrderBy><FieldRef Name='Modified' Ascending='False' /></OrderBy><RowLimit>100</RowLimit>

And my JSOM call:

 var context = SP.ClientContext.get_current();
 var web = context.get_site().get_rootWeb();
 var list = web.get_lists().getByTitle(listName);
 var camlQuery = new SP.CamlQuery();
 var items = list.getItems(camlQuery);

But when I run it I get the error saying, I have hit the threshold limit:

Request Failed: The attempted operation is prohibited because it exceeds the list view threshold enforced by administrator.

Now am using View Scope as RecursiveAll because the items I am interested is inside sub folders of the year folder. If I edit the caml query and change the View scope to default, my caml query works perfectly but since scope is now set to current folder, it will only return me the 4 folders but not the items inside. Now is this a limitation in the way caml query works that if I put View Scope as RecursiveAll , it expands the search to whole list? Is there a way to make the caml query work with the above set up?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.