0

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.)

  • What is the error you are getting? – sharepoint_geek May 2 at 16:37
  • I'm getting a ServerException where the ServerExceptionTypeName is the SPThrottlingException. (Sorry I don't have the debugger easily accessible right now.) – Ants May 3 at 4:20
2

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)

  • Given how Sharepoint is so poorly documented, I've been trained since 2003 to give more credence to StackOverflow, blog posts, MSDN forums, and SharePoint related books. But, yes, it does make sense that in this case, the MSDN documentation seems to be more correct. – Ants May 3 at 4:27
  • it has gotten better over the years, but yeah, I know what you're saying. – Derek Gusoff May 3 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.