Using Caml, I'm trying to pull back all items from a SharePoint Online site that have been modified in the last year. The query results in an error that states: "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator." This threshold is 5000 items on SharePoint Online, and it cannot be modified as far as I can tell after discussing with a SharePoint admin.
This error is fairly well documented, but none of the solutions I've looked at have addressed my question.
I've gotten past this issue before by using the <RowLimit></RowLimit>
tag inside my Caml query and by setting a $position
variable that keeps track of where I am after every chunk of 5000 items. See below for the query that is working for lists with more than 5000 items:
$query = @"
<View Scope="RecursiveAll">
<Query>
<OrderBy><FieldRef Name="Created" Ascending="false"/></OrderBy>
</Query>
<RowLimit Paged="TRUE">5000</RowLimit>
</View>
"@
The above works. However, it simply gets everything from a certain library. What I'm trying to do now is get everything that's been modified in the past year. Here's what I have:
$oneYearAgo = (Get-Date).AddDays(-365)
$oneYearAgoString = $oneYearAgo.ToString("yyyy-MM-ddTHH:mm:ssZ")
$query = @"
<View Scope='RecursiveAll'>
<Query>
<OrderBy><FieldRef Name='Modified' Ascending='false'/></OrderBy>
<Where>
<Geq>
<FieldRef Name="Modified"/>
<Value Type="DateTime">
$oneYearAgoString
</Value>
</Geq>
</Where>
</Query>
<RowLimit Paged="TRUE">5000</RowLimit>
</View>
"@
This one returns that "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator" error, though the logic outside of the two Caml queries is almost identical.
Is there something wrong with my Caml query?