Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Posts Tagged ‘odata’

OData substringof Examples

Posted by Paul on July 3, 2015

In this article we can explore OData examples for string method substring.

substringof

This filter returns the field values containing specified string.

Please note that the method-name is case sensitive & only lower case works.

Example

Please create the data as shown below.

image

Following is the query URL.

http://sharepoint/_api/Web/Lists/GetByTitle(‘Contacts’)/Items?$filter=substringof(‘avv’,Title)

Following is the result using Chrome browser.

image

image

Please note that we are querying against column named Title. The column name appears second after the value.

More Examples

You can now try a non-existing string.

Following is the URL:

http://sharepoint/_api/Web/Lists/GetByTitle(‘Contacts’)/Items?$filter=substringof(‘ABC’,%20Title)

The result is empty XML packet.

image

image

Please note that the operation name should be in lower-case.

References

https://msdn.microsoft.com/en-us/library/gg309461.aspx

Summary

In this article we have explored OData examples for string method substring.

Advertisements

Posted in SharePoint, SharePoint 2013 | Tagged: , | Leave a Comment »

OData startswith Examples

Posted by Paul on June 30, 2015

In this article we can explore OData examples for string method startswith.

startswith

This filter returns the field values starting with specified string.

Please note that the method-name is case sensitive & only lower case works.

Example

Please create the data as shown below.

image

Following is the query URL.

http://sharepoint/_api/Web/Lists/GetByTitle(‘Contacts’)/Items?$filter=startswith(Title,’Bran’)

Following is the result using Chrome browser.

image

image

Please note that we are querying against column named Title.

Another Example

Now let us try with an non-existing string.

Following is the query URL.

http://sharepoint/_api/Web/Lists/GetByTitle(‘Contacts’)/Items?$filter=startswith(Title,’ABCD’)

Following is the result using Chrome browser which shows no-results.

image

You can now play with more examples.

image

Please note that the operation name should be in lower-case.

References

https://msdn.microsoft.com/en-us/library/gg309461.aspx

Summary

In this article we have explored OData with method startswith.

Posted in SharePoint, SharePoint 2013 | Tagged: , , | Leave a Comment »

OData and Numeric Comparison Filters

Posted by Paul on June 21, 2015

In this article we can explore OData using Numeric Comparison filters.

Numeric Comparison Filters

Following are the Numeric Comparison filters available with OData

lt Less Than
le Less Than or Equals To
gt Greater Than
ge Greater Than or Equals To
eq Equal To
ne Not Equal To

Data Preparation

To proceed with the example I encourage you to create a Contacts list with a column named Age of type integer. Please fill some data appropriately.

clip_image002

eq Filter

Following is the example of using Equal filter where the column Age is equal to 30.

http://server/_api/Web/Lists/GetByTitle(‘Contacts’)/Items?$filter=Age eq 30

The result was one list item as per my data.

clip_image004

clip_image006

Please note that uppercase (EQ) won’t work.

ne Filter

Following is the example of using Not Equal filter where the column Age is not equal to 30.

http://server/_api/Web/Lists/GetByTitle(‘Contacts’)/Items?$filter=Age ne 30

Obviously it returned a lot of items.

clip_image008

lt Filter

Following is the example of using Less Than filter.

http://server/_api/Web/Lists/GetByTitle(‘Contacts’)/Items?$filter=Age lt 10

As there are no items with Age less than 10, my result was empty.

clip_image010

Similarly you can play with the remaining Arithmetic operators.

References

https://msdn.microsoft.com/en-us/library/gg309461.aspx

Summary

In this article we have explored Numeric Comparison filters of OData on SharePoint 2013 REST services.

Posted in SharePoint, SharePoint 2013 | Tagged: , , , , | Leave a Comment »

OData with REST

Posted by Paul on June 19, 2015

In this post we can get introduced to OData along with REST.

REST

REST stands for Representational State Transfer. It is a stateless communication protocol using HTTP and ensuring HTTP verbs are accurately used for CRUD operations. Please see references for more information.

SharePoint 2013 supports REST services which enabled an easier & better communication from client-side. We can use REST for:

1. Getting site information using URL

2. Getting list information using URL

3. Getting list items using URL

An example of REST URL is:

http://server/_api/Web/Lists/GetByTitle(‘Contacts’)

But, REST have drawbacks on querying and filtering. For example, using the URL format it is difficult to filter items.

OData

OData stands for Open Data Protocol. OData allows Filtering & Interoperability on REST services. We combine OData along with REST methods.

So REST + OData allows gives more flexibility in querying & filtering items.

Selecting Columns using OData

Following OData sample specifies selection of Title column only.

http://server/_api/Web/Lists/GetByTitle(‘Contacts’)/Items?$select=Title

image

FYI: The above query without the Title selection is as following.

http://server/_api/Web/Lists/GetByTitle(‘Contacts’)/Items

image

Although REST is stateless like HTTP, the sessions are stored in client-side and transferred back and forth from web server.

References

http://www.c-sharpcorner.com/UploadFile/40e97e/rest-enable-web-services-in-sharepoint/

https://en.wikipedia.org/wiki/Open_Data_Protocol

https://msdn.microsoft.com/en-us/library/office/fp142385.aspx

Summary

In this post we have explored usage of REST with OData in SharePoint 2013.  In the upcoming posts we can explore more options in OData.

Posted in SharePoint, SharePoint 2013 | Tagged: , , , | Leave a Comment »