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
- Specify Host Web URL
- Select SharePoint -Hosted as hosting model
Wait while Visual Studio configure 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: Adding 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 which can be queried from the list, check for this property and make sure it exists before proceed 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 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
Build the Solution and Deploy it
Trust the App when asked for
Provide the credentials when asked for
Click on “Manage Threshold Limits”
See to 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.
by Prashant Bansal via Everyone's Blog Posts - SharePoint Community
No comments:
Post a Comment