Question

I am not understanding why this CAML query from CSOM is getting throttled:

<Query>
  <Where>
    <And>
      <Eq>
        <FieldRef Name="Period" />
        <Value Type="String">JAN</Value>
      </Eq>
      <Eq>
        <FieldRef Name="Year" />
        <Value Type="Integer">2017</Value>
      </Eq>
    </And>
  </Where>
  <View Scope="RecursiveAll">
    <RowLimit>256</RowLimit>
  </View>
</Query>

but not this one:

<View Scope="RecursiveAll">
  <Query>
    <Where>
      <And>
        <Eq>
          <FieldRef Name="Period" />
          <Value Type="String">JAN</Value>
        </Eq>
        <Eq>
          <FieldRef Name="Year" />
          <Value Type="Integer">2017</Value>
        </Eq>
      </And>
    </Where>
  </Query>
  <RowLimit>256</RowLimit>
</View>

I am using those CAML queries within my CSOM code that in pseudo code looks like this:

using (var context = new ClientContext(siteUrl))
{
    var query = CamlQuery.CreateAllItemsQuery(256);
    query.ViewXml = queryXML; // see above
    list.GetItems(query);
    context.ExecuteQuery();
}

The reason why I reformatted the CAML to the version at the top is because of this CodeProject article: Overcoming the List View Threshold in SharePoint CAML queries.

(As an aside, my reading of the CAML Schema is that the Query is a child of View and the other way around as shown in the CodeProject article. But considering the number of times that article popped up from various other forums, I thought that it would have correct information.)

Was it helpful?

Solution

Your syntax on the top example is wrong. The View element should wrap the Query element. Your second example is correct. The CodeProject article is misleading because it omits the View element altogether in most of its examples.

When a CAML query is malformed, SharePoint will just silently discard it, and gives you an "All Items" query. That's why you're hitting the threshold.

When in doubt, always trust the Microsoft documentation over some random guy's blog.

https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee534956(v%3Doffice.14)

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top