$skip does not work in SharePoint 2013 OData REST Endpoint for list item retrieval


This came as a surprise to me seeing the OData URI query option “$skip” does not work, while trying to implement pagination logic on list using SharePoint 2013 REST API. Although this works perfectly well with the old ListData.svc…:(

So here are some alternatives that can help you in your paginations:

1. Using $filter URI query option:

/_api/web/Lists/GetByTitle(‘ODataList’)/items?$filter=Id gt {SkipValue}&$top={TopValue}

ex. /_api/web/Lists/GetByTitle(‘ODataList’)/items?$filter=Id gt 2&$top=3  –>gives you the records with IDs 3,4,5.

2. Using the _next link at the end of the response

/_api/web/Lists/GetByTitle(‘ODataList’)/items?$top={TopValue}

ex. /_api/web/Lists/GetByTitle(‘ODataList’)/items?$top=10 –> gives you records with Skip and top value as 10. If you go to the end of the response, you will get the “nextlink” in the following format:

<link rel=”next” href=”{Server URL}/_api/web/Lists/GetByTitle(‘ODataList’)/items?%24skiptoken=Paged%3dTRUE%26p_ID%3d5&amp;%24filter=Id+gt+2&amp;%24top=3″ />

But the skipvalue for pagination is taken as the value give for $top parameter.

3. Use the ListData.svc

/_vti_bin/ListData.svc/ODataList?$skip=2&$top=1&$orderby=Id

skip and top works perfectly here and the response is in the AtomPub format.

Bottom line: $skip won’t work with the new SP 2013 REST endpoints for list item retrievals. You will have to go with one of the alternatives above. 

Hope this was helpful.

Extract the Term Sets and their custom properties using CSOM in SharePoint 2013


The code snippet below will help you to query the SharePoint 2013 Term store using CSOM (ECMAScript):

//Get the Current SP Context

var context = SP.ClientContext.get_current();

 

//Get the Current SP Taxonomy Session
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);

 

//Get the Term Stores instance
var termStores = taxSession.get_termStores();

 

//Get the exact Term Store you would like to query

//To get this…goto your term store, inspect the HTML element corresponding to your Term Store in your

//browser and you will get this ID

//Check the screenshots below
var termStore = termStores.getByName(“Taxonomy_foSyfMpI/9yqdQsdxwuVGA==”);

 

//Get the required Term Set you want to fetch

//To get this…goto your term store, inspect the HTML element corresponding to the Term in your browser and check the ID of the <li> element
var termSet = termStore.getTermSet(“8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f”);

 

//Load the termSet into the context
context.load(termSet);

 

//Execute the Query
context.executeQueryAsync(function(sender,args){
//Contains the Terms and their custom properties

//Check the screenshot below 
},function(sender,args){

//Any exception messages

console.log(args.get_message());

});

Screenshots:

Image

Fig: Extracting the TermStore ID

Image

Fig: Extracting the Term ID

Image

Fig: Execution the above script in chrome browser Developer Toolbar Javascript Console (F12)

Image

Fig: The execution results showing the Custom Property key and value

For further reference on extracting the terms, termsets and groups refer here:

http://cann0nf0dder.wordpress.com/2013/04/09/accessing-taxonomy-term-store-with-jsom/

Hope this helps.