Do you know to do data you need CAML?

Updated by Brady Stroud [SSW] 1 year ago. See history

123

CAML is the XML definition for all things in SharePoint, in deployment, and in creating templates, CAML is the only format. In SharePoint development, you will also need to know CAML, in particular, how to write a query in CAML.

<query>
<orderby>
<fieldref name="Modified" ascending="FALSE"></fieldref>
</orderby>
<where>
<and>
<neq>
<fieldref name="Status"></fieldref>
<value type="Text">Completed</value>
</neq>
<isnull>
<fieldref name="Sent"></fieldref>
</isnull>
</and>
</where>
</query>

Figure: Example of CAML query

You can see - CAML is essentially the same as SQL WHERE syntax, but wrapped in an XML format.

Problems with CAML:

  1. CAML is XML and is case sensitive – including attributes names.
<Query>
<Where>
<Or>
<Eq>
<FieldRef name="Status" />
<Value Type="Text">Completed</Value>
</Eq>
<IsNull>
<FieldRef Name="Status">
</IsNull>
</Or>
</Where>
</Query>

Figure: Example of CAML query

  1. SharePoint is not good at telling you if you made a mistake with your CAML query.
Image

❌ Figure: Debug error message

  1. Hard to debug.

Tip: Use 3rd Party tools - U2U CAML Query Builder

Image

✅ Figure: U2U CAML Query Builder

Note: U2U CAML Builder is the best tool that we have. There are some occasional UI and interface issues, but for creating CAML and testing it against live SharePoint lists it gets the job done. And it’s free!

acknowledgements
related rules