This SharePoint CAML tutorial explains, how to retrieve list items from SharePoint Online/2013/2016 based on ID. We will see how to filter the CAML query by list item ID in SharePoint Online or SharePoint 2016/2013.
In SharePoint, the best approach to get the data from SharePoint a list is to query those using either the SharePoint Server Object model or the client object model. Using queries you guarantee that only list items you really need are retrieved from the database and constructed to objects by SharePoint.
Most of the time you don’t need the full collection of list items, so it does not point to ask all the items and then use only a few of these. Let’s see how we can query SharePoint lists using the Client object model.
SharePoint 2010 (caml query to retrieve sharepoint list item by ID)
Below is the CAML query to retrieve the list item by ID in SharePoint 2010.
<Query><Where><Eq><FieldRef Name="ID" /><Value Type="Counter ">' + ID + '</Value></Eq></Where></Query>
SharePoint 2013/Online (caml query to retrieve sharepoint list item)
Below is the CAML query to retrieve list items by ID in SharePoint 2013/Online.
<Query><Where><Eq><FieldRef Name="ID" LookupId="TRUE"/><Value Type="Text">' + ID + '</Value></Eq></Where></Query>
I am using an ajax / Jquery script calling the getlistitems() method to filter the results using a query in SharePoint.
Use the following procedure to create a sample.
Step 1: Navigate to your SharePoint 2013 site.
Step 2: From this page select Site Actions | Edit Page:
Edit the page, go to the “Insert” tab in the Ribbon and click the “Web Part” option. In the “Web Parts” picker area, go to the “Media and Content” category, select the Script Editor Web Part and press the “Add button”.
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 SharePoint 2013 Online
- CAML Query Builder for SharePoint 2013/2016/Online
- 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
In this article, I have explained in detail, how to retrieve List items from SharePoint 2013 based on the “ID” column value using CAML Query.
Solutions. I am currently working on Sharepoint 2010, MOSS 2007, Sharepoint 2013,Sharepoint 2013 App Dev, C#, ASP.NET, and SQL Server 2008.
Download SharePoint Online Tutorial PDF FREE!
Get update on Webinars, video tutorials, training courses etc.