SharePoint 2013: How to Overcome List Threshold Limits Using OData Continuation

While working with a SharePoint Large List, we all must have encountered the issues with restricted access to the list, due to List Threshold Limits.

In order to demonstrate this solution, I am making use of SharePoint Hosted App, as shown in the below steps:

  • Create SharePoint App Project by choosing "App for SharePoint 2013" Project Template.


  • Specify Host Web URL.
  • Select SharePoint Hosted as hosting model.


Wait while Visual Studio configures the Project for you.

 

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.


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.



So, the final UI would look like as below-

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: Add a helper function “getQueryStringParameter()” that will help us to extract the Query String Parameters.

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 that can be queried from the list. Check for this property and make sure it exists, before proceeding further.

 

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



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 because 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.



Build the Solution and Deploy it.



Trust the App when asked.


Provide the credentials when asked.


Click on “Manage Threshold Limits”.


See the Result Panel and, sure enough, you will find records adding continuously based on the Paginated REST Calls, driven by Odata Continuation.



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.