Wednesday, June 4, 2008

CAML Queries in Sharepoint

CAML Queries in sharepoint

Looking for a way to filter lists in sharepoint, then caml will come to your help.

Complex CAML Queries such as the following can be made:

<view><query><orderby><fieldref name="Event_x0020_Date" ascending="TRUE"></orderby><where><or><eq><fieldref name="Lookup_x0020_Status"><value type="Text">{all}</value></eq><and><and group="true"><eq><fieldref name="ATS_x0020_Status"><value type="Text">Active</value></eq><or><contains><fieldref name="Title"><value type="Text">{k}</value></contains><contains><fieldref name="Event_x0020_Description"><value type="Note">{k}</value></contains></or></and><and group="true"><eq><fieldref name="Lookup_x0020_Status"><value type="Text">Active</value></eq><or><contains><fieldref name="Lookup_x0020_Description"><value type="Note">{k}</value></contains><contains><fieldref name="Title"><value type="Text">{k}</value></contains></or></and></and></or></where></query></view>

Here is a nice msdn example.. http://msdn.microsoft.com/en-us/library/ms196939.aspx

and can only be used to compare 2 boolean expressions. Doing otherwise results in a runtime error in Sharepoint Services (described by the ever-helpful "Cannot complete this action. Please try again." message).





If you would like to do some advanced filtering it is better to get a Caml Viewer Tool such as stramitCamlViewer.












Using sharepoint designer to group Filters is the best way of grouping filters for doing some simple grouping.

It would be great if microsoft can provide a advanced filtering option in the future sharepoint releases.



Hope this helps.








No comments: