CAML know as Collaborative Markup Language is an XML based language for querying and updating SharePoint objects like List and Libraries. CAML helps us retrieving items from a SharePoint list based on various conditions, we can also put order by, can also limits items returns from the query etc. We can use Caml query builder SharePoint 2013 Online to write caml query.
Here we will discuss how we can use CAML Query designer tool to generate CAML queries in SharePoint 2013.
Download Install and Use SharePoint CAML Query Designer
First download CAML designer from this URL.
To start connecting to a site click on CONNECTION, then click on the particular button on which environment, Here I clicked on Office 365 button to connect to the Office 365 SharePoint Online site. Then it will ask you to enter the Username and Password and then click on Connect as shown in the fig below:
Once the site loaded, all the SharePoint object will be loaded. Click on the particular list for which you want to generate the CAML query. Then click on the ViewFields and drag and drop the fields you want to query.
Then click on the Where to generate the conditions. Here I am trying to filter based on the First Name column. So I drag and drop the First Name column. Writer click on the circle to see the operators like below:
Now Here I gave the condition as First Name contain “Item”. Then the query will be modified and displayed like below:
You can go to the Query Options tab and change various options. I have changed here the Row limit. And it will show the query like below:
You can see the test results in the Test tab like below:
You can copy the code generated by Server OM code, CSOM.NET code. CSOM Rest API code, Web Services code & PowerShell code. You can take the code from various tabs.
SPList spList = spWeb.Lists.TryGetList(“TestList”);
if (spList != null)
SPQuery qry = new SPQuery();
<FieldRef Name=’First_x0020_Name’ />
qry.ViewFields = @”<FieldRef Name=’First_x0020_Name’ /><FieldRef Name=’Title’ /><FieldRef Name=’ID’ />”;
qry.RowLimit = 100;
SPListItemCollection listItems = spList.GetItems(qry);
Generate Site Data Query using CAML Designer 2013:
We can also generate Site Data Query by using the CAML Designer. Choose Site Data Query option from the top and then you can see see the query like below:
SPSiteDataQuery qry = new SPSiteDataQuery();
<FieldRef Name=’First_x0020_Name’ />
qry.ViewFields = “<FieldRef Name=’First_x0020_Name’ /><FieldRef Name=’Title’ /><FieldRef Name=’ID’ />”;
qry.Lists = “<Lists ServerTemplate=’100’/>”;
DataTable resultTable = spWeb.GetSiteData(qry);
You may like following SharePoint CAML Query examples:
- How to Use CAML Query for Boolean field for SharePoint 2013/2016/Online Object Model CSOM
- Download, Install and Use CAML Query Helper in SharePoint Online/2013/2010/2007
- CAML Query Builder for SharePoint 2013/2016/Online
- Filter CAML Query by List Item ID in SharePoint Online/2013/2016
- SharePoint CAML Query Order by Example with Dropdown in SharePoint Online/2013/2016
- Task assigned to user or current user groups in SharePoint 2010 using CAML query
Hope this will be helpful for you to understand CAML query builder for SharePoint 2013 Online.
I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SPGuides.com
Download SharePoint Online Tutorial PDF FREE!
Get update on Webinars, video tutorials, training courses etc.