
Common List Operations
❘
375
You can learn more about CAML on MSDN at http://msdn.microsoft.com/
en-us/library/ms426449.aspx
. Building CAML queries can be fairly compli-
cated. It is recommended that you use a CAML query builder to help you build
the correct query. A number of community CAML query tools are available on
CodePlex. You can fi nd the one that works best for you by searching CodePlex,
at
www.codeplex.com/site/search?query=caml.
SharePoint provides a method, createAllItemsQuery, which returns a valid CAML string that
returns all items. If you look at the
createAllItemsQuery method in SP.Debug.js or debug the
code, you will see the following CAML string that is returned:
<View Scope=\”RecursiveAll\”>
<Query></Query>
</View>
After you specify the CAML query, you load the list items query on the context, and then execute
the query on the server asynchronously by calling
executeQueryAsync.
Once the query returns from the server, in this case the
ReadListItemsSucceeded method is called.
Iterate over the returned items by getting a reference to the enumerator and calling the
moveNext
method in a
while loop. On each iteration of the loop, you can get the current list item using the
get_current method of the item. Finally, once you have a reference to the item, you can call the
get_item method, passing in the string name of the fi eld you want. Add the following code to the
ListOperations.js ...