SharePoint 2013 : How to overcome List Threshold Limits using OData Continuation
While working with SharePoint Large List we all must have encountered the issues with restricted access to the list due to List Threshold Limits.
In this article we see the solution to this problem that can be implemented using OData Continuation in conjunction with REST API.
In order to demonstrate this solution I am making use of SharePoint Hosted App as in shown in below steps-
- Create SharePoint App Project by choosing “App for SharePoint 2013” Project Template
https://howtodowithsharepoint.files.wordpress.com/2015/11/110.png?w=300&h=208
- Specify Host Web URL
- Select SharePoint -Hosted as hosting model
https://howtodowithsharepoint.files.wordpress.com/2015/11/25.png?w=300&h=217
Wait while Visual Studio configure the Project for you
https://howtodowithsharepoint.files.wordpress.com/2015/11/31.png?w=300&h=118
In order to showcase the data access from a Large SharePoint List, I have added a list with 1 Lakh items in it and default Threshold limits are still intact
https://howtodowithsharepoint.files.wordpress.com/2015/11/41.png?w=300&h=265
Now add some HTML for the UI in the Start Page of the App (default.aspx)
Step 1: Adding container for the HTML Button
Step 2: Adding HTML Button that will execute the code in action
https://howtodowithsharepoint.files.wordpress.com/2015/11/51.png?w=300&h=92
So the final UI would look like as below-
https://howtodowithsharepoint.files.wordpress.com/2015/11/6-1.png?w=300&h=112
Now add some JavaScript code in App.js File
Step 3: Bind the event handler with the HTML Button in “document.ready()” function
Step 4: Adding a helper function “getQueryStringParameter()” that will help us to extract the Query String Parameters
https://howtodowithsharepoint.files.wordpress.com/2015/11/61.png?w=300&h=57
In the Callback function “oDataContinuations” we have following steps executing-
Step 5: Getting value of “SPHostUrl” by using “getQueryStringParameter()” helper function
Step 6: Getting value of “SPAppWebUrl” by using “getQueryStringParameter()” helper function
Step 7: Loading “SP.RequestExecutor.js ” JavaScript file as we need to issue a Cross Domain Call from SharePoint App to Host Web
Step 8: Prepare the URL to execute the Cross Domain Call to the Large List present in the Host Web
Step 9: Instantiate the object of Request Executor based on the App URL
Step 10: Calling “executeAsync” method of Request Executor Object
This function needs a JSON object with configuration values like
url: Specify the Url to execute Cross Domain Call
method: Specify the Request access method (GET or POST)
datatype: Specify the expected return type of the response (JSON)
headers: Specify the Request Headers
Step 11: On successful execution of this request, response object would return back with a property “__next” which contains the direct URL to the next set of records which can be queried from the list, check for this property and make sure it exists before proceed further
https://howtodowithsharepoint.files.wordpress.com/2015/11/7-1.png?w=300&h=144
Step 12: Get the Url to the next result set
Step 13: Call the “getItems()” method recursively with the new Url returned by response object “__next” property
https://howtodowithsharepoint.files.wordpress.com/2015/11/71.png?w=300&h=125
With this we are all done with the code.
But before we move any further we need to allow the permission for the App on Host Web since we need to query the data from the list which is hanging inside the Host Web.
Step 1: Go to App Manifest File => Permission Tab
Step 2: Specify Read permission
https://howtodowithsharepoint.files.wordpress.com/2015/11/81.png?w=300&h=106
Build the Solution and Deploy it
https://howtodowithsharepoint.files.wordpress.com/2015/11/91.png?w=300&h=64
Trust the App when asked for
https://howtodowithsharepoint.files.wordpress.com/2015/11/101.png?w=300&h=175
Provide the credentials when asked for
https://howtodowithsharepoint.files.wordpress.com/2015/11/111.png?w=300&h=179
Click on “Manage Threshold Limits”
https://howtodowithsharepoint.files.wordpress.com/2015/11/121.png?w=300&h=112
See to the Result Panel and sure enough you will find records adding continuously based on the Paginated REST Calls driven by Odata Continuation
https://howtodowithsharepoint.files.wordpress.com/2015/11/131.png?w=300&h=98
This is a simple demonstration to showcase how we can effectively make use of Paginated REST Calls driven by Odata Continuation to overcome issues related to List Threshold Limits.
Hope you find it helpful.