0
votes

I'm not sure I have a syntax error here in my CAML Query or I am misunderstanding how the API works but I have a very large document library in which I am trying to identify items that have had no compliance / retention label set.

My query is trying to return any item in the library that does not have the compliance retention label set to "Test". This is the query but regardless of rowlimit, the console app returns the threshold error... "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator."

<View Scope='RecursiveAll'><RowLimit>20</RowLimit><Query><Where><Neq><FieldRef Name='_ComplianceTag'/><Value Type='String'>Test</Value></Neq></Where></Query></View>

I have been trying the most basic query and I can confirm this works...

<View Scope='RecursiveAll'><RowLimit>20</RowLimit></View>

But as soon as I add element to the CAML, I get the error. It seems once the query is added it ignores my row limit. The plan is to bring the items back in small batches and apply the label. I've already built a console app which uses the SetComplianceTag to library method. This applies Tags to everything in the library but unfortunately my library is so large we found it missed a few.

Any insights would be much appreciated.

1
I should not I have read in a number of similar questions, in most of which part of the solution is to index the column. At the moment I cant be certain our client will be willing to do that so I'm trying to explore any options that are out there without column indexing.andy moore

1 Answers

1
votes

Having read further I now understand the query is executed on the entire list so limits apply regarless of the rowLimit in your CAML. I have now copied and adapted what Piyush K Singh has done in the tutorial linked below. There is a ListItemCollectionPosition object which can handle breaking your API request into batches the size specified in your row limit. I then loop through each batch looking for the items that match my specified conditions...

https://piyushksingh.com/2016/12/04/query-listitems-in-batches-sharepoint-online/

Thanks Piyush!