SharePoint: List Views (CAML Queries)


Collaborative Application Markup Language (CAML) is a schema used in SharePoint to query list data. Viewing, sorting, and grouping columns, that’s straight-forward. One or two filter conditions, also straight-forward. But when three or more conditions are applied, the logic may get a bit murky. Because the UI hasn’t really changed over the years, it still doesn’t reveal exactly how the filters are structured:

  • E.g., three filter conditions.

Are the conditions evaluated sequentially? Or are they evaluated at once? If we use the SharePoint REST APIs, then we can peek under the hood. From the resulting XML, the view logic is the value of the ListViewXml child node:

  • E.g., REST API query of list views.
https://<tenantName>.sharepoint.com/_api/lists('<listGuid>')/views
  • E.g., REST API export of result XML.

After copying and formatting the XML into an editor, the filter structure is revealed. Basically, as filters are appended, the conditions are evaluated in pairs. For three filters, the first two conditions are evaluated, then their result is evaluated with the final condition:

  • E.g., CAML Query of view filters.

However, if another condition is added, then the nesting just gets deeper:

  • E.g., four filter conditions.
  • E.g., CAML Query of view filters.

Conclusion:
Most people likely aren’t creating views with robust filters, but when it is necessary, it helps to visualize how the conditions are structured… More than one filter and things are evaluated in pairs.

“Too much agreement kills chat.”

Eldridge Cleaver

#blacklivesmatter

Leave a comment