Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

Sharepoint 2013 : Overview of The Client-Side Object Model and Rest APIs - REST and OData (part 2) - Filtering and Selecting

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
8/17/2014 9:27:44 PM

Filtering and Selecting

When you query for data it’s important to ask for only the data you really need. This keeps payload sizes down and speeds up delivery of the data. _Api uses OData semantics to let you do this by filtering records and selecting properties you want. The common operators you can use for manipulating the result set include the following:

  • $filter, for filtering results
  • $select, for selecting properties to return
  • $expand, for expanding properties to return
  • $orderby, for ordering results
  • $top, for taking the top X results

The simplest way to learn about these operations is to try them out for yourself, as shown in the following exercise.


TRY IT OUT: OData Operations on Data
In this exercise you try out querying and filtering for data using the REST/OData _Api in SharePoint 2013.

1. Create a new list in your SharePoint 2013 site by clicking Site Contents from the Quick Launch navigation.

2. Click Add an App.

3. Choose Custom List and call it Movies.

4. After the list is created, add some list items to it of your favorite movie titles.

5. Modify the URL to navigate to the following URI. Review the payload XML that is returned:

https://servername/sitename/_api/Web/Lists/MoviesList/Items
6. Modify the URL by adding (1) on the end (shown in the following code). This returns the first item in the list:

https://servername/sitename/_api/Web/Lists/MoviesList/Items(1)
7. Modify the URL and add a $filter parameter like the following, specifying the title of one of the movies you added earlier:

?$filter=Title eq 'Aliens'
8. Add a $select parameter to just select the Title property of the list item:

https://servername/sitename/_api/Web/Lists/_api/Lists/ /Items?
$filter=Title eq 'Aliens'&$select=Title
You should see a payload similar to the following:
<?xml version="1.0" encoding="utf-8" ?> 
<feed xml:base="https://servername/sitename/_api/"
xmlns="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
<id>0d01b697-f8f4-496a-bc66-81e4ab7d8208</id>
<title />
<updated>2012-11-03T07:07:21Z</updated>
<entry m:etag=""2"">
<id>f6126125-fddb-4651-bedd-d797c6ef06f4</id>
<category term="SP.Data.MoviesListItem"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit"
href="Web/Lists(guid'f57d3ddc-4522-4145-a0fe-72abbd6ea8fc')/Items(1)" />
<title />
<updated>2012-11-03T07:07:21Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:Title>Aliens</d:Title>
</m:properties>
</content>
</entry>
</feed>
Notice that only the Title property is returned.

9. Modify the querystring as follows to order your movie titles alphabetically:
?$select=Title&$orderby=Title
10. Modify the querystring as follows to just retrieve the first movie:
?$select=Title&$orderby=Title&$top=1
How It Works

In this exercise you queried SharePoint list data using the REST/OData API. When a request is made to SharePoint via this API, SharePoint uses WCF Data Services support for OData to parse and interpret the query on the URL. It then uses that information to translate the query into an internal SharePoint list query (called a CAML query) and executes the query. By adding OData support parameters to the URL you are able to refine the query you make to SharePoint and just return the data you specifically need.
Other -----------------
- Sharepoint 2013 : Integrating Apps for Office with SharePoint (part 2) - Apps for Office Integrated with an App for SharePoint
- Sharepoint 2013 : Integrating Apps for Office with SharePoint (part 1) - Standalone Apps for Office
- Sharepoint 2013 : The Office JavaScript Object Model (part 3) - App Security
- Sharepoint 2013 : The Office JavaScript Object Model (part 2) - Functional Capabilities by Office Client,Mailbox-based Apps
- Sharepoint 2013 : The Office JavaScript Object Model (part 1) - Document-based Apps
- SQL Server 2012 : Understanding Latches and Spinlocks (part 3) - Latching Example - With Latching
- SQL Server 2012 : Understanding Latches and Spinlocks (part 2) - Latching Example - Without Latching
- SQL Server 2012 : Understanding Latches and Spinlocks (part 1) - Latching Example
- SQL Server 2012 : Latches and Spinlocks - Symptoms (part 2) - Measuring Latch Contention, Measuring Spinlock Contention , Contention Indicators
- SQL Server 2012 : Latches and Spinlocks - Symptoms (part 1) - Recognizing Symptoms
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server