Home > CMS- Content Management System > Sharepoint > How to read more than 5000 list items in office 365/ SharePoint 2013

How to read more than 5000 list items in office 365/ SharePoint 2013

This post was most recently updated on August 5th, 2024

We know that in SharePoint, number of items we can fetch at one time which should not be more than 5000 items that default architect of SharePoint list. So sometime there may be the condition where list reaches 5000 item and need to load all list item on custom dashboard page.  In this case getting all 5000 item on the page is problematic and page load performance gets affected.

When list/view reach 5000 items following friendly error massage is arise in list information.

When we Query large list by rest “/_api/web/lists/getbytitle (‘<list title>’)/items” on the list which has more than 5000 items, you will get following exception “Request failed. The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator”.

Below I share code to load threshold exceed list on page with better page loading performance.

Steps: Page level

  • Create page and add following datatable css and js.

    <link rel=”stylesheet” type=”text/css” href=”https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css” />
    <script src=”https://code.jquery.com/jquery-1.12.4.js” type=”text/javascript”></script>
    <script type=”text/javascript” src=”https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js”></script>

  • Create table with header according to SharePoint list.

Steps: JS Level

  • Step 1: We need to get total item count from the list in order to read list data in the number of batches. We are using GetItemCount () function to get the total item count.
  • Step 2: Next step create rest service url by splitting rest call according to item count of GetItemCount () function. Check item count if item count is above 5000 then we split calling with 1000 item per call top=1000 for better performance. Otherwise, we call as usual i.e. top=5000.
  • Step 3: Process each item of threshold list by repeatedly calling getJSONDataFromUrl () function. GetJSONDataFromUrl () function gives Ajax json object.

Final Screen shot 

Click here to follow the steps to add Column level filters in the data table

Reference:

https://sharepoint.stackexchange.com/questions/217254/rest-to-read-more-than-5000-items-from-document-library/217451#217451

This Article is TAGGED in , , . BOOKMARK THE permalink.

15 thoughts on “How to read more than 5000 list items in office 365/ SharePoint 2013

  1. If i add any filter parameters it’s throwing me error. Eventhough filtered columns are being indexed.

    It’s very urgent can you help please.

    1. It will fail for large list with filter event columns is indexed, So avoid filter get all the data and filter the object using JavaScript. Hope this will helps.

  2. Please tell us how to add export button like excel,pdf etc in above example.

    I tried below code but its giving error ” Cannot perform DeepCopy() because a circular reference was encountered”

    var table = $(‘#table_id’).DataTable({
    buttons: [
    ‘copy’, ‘csv’, ‘excel’, ‘pdf’, ‘print’
    ]
    } );

  3. Thanks for your response but i am able to get data by adding “aaData”: items before line

    “aoColumns”: [{
    “mData”: “ParentDocName”
    }, {
    “mData”: “ChildDocNames”
    }, {
    “mData”: “ParentDocId”
    }, {
    “mData”: “ParentListName”
    }, {
    “mData”: “Modified”,

    but again a problem is that table got initialize each time function runs. Please provide me solution that can stop repeat initialization of Data table and can get data

    1. Thank you, Keshav for your comment. We updated whole code to process of fetching list items. I hope this will help you.

      1. Thanks, the code is working fine but since I have >50k items in the list so getting all items one by one in internet explorer got crashed. Since you have good knowledge of Jquery, Is it possible to get only those items in first page which are selected for a page like 10 items in your screenshot and again 10 items in second pagination page

  4. Hi I am not getting any data. Please help me if anything wrong

    MYCODE:

    $(document).ready(function () {
    loadMyItems();
    });

    function loadMyItems() {
    var siteurl = _spPageContextInfo.siteAbsoluteUrl;
    var RestUrl = siteUrl + “/_api/web/lists/getbytitle(‘BP_EDP_GDMP_RELATIONSHIPLIST’)/items?$select=ParentDocName,ChildDocNames,ParentDocId,ParentListName,Modified&$top=5000″;
    var ItemCount = ”;
    $.ajax({
    url: siteurl + “/_api/web/lists/getbytitle(‘BP_EDP_GDMP_RELATIONSHIPLIST’)/ItemCount”,
    method: “GET”,
    async: false,
    headers: { “Accept”: “application/json; odata=verbose” },
    success: function (data) {
    ItemCount = data.d.ItemCount;
    },
    error: function (data) {
    console.log(data);
    }
    });
    if (ItemCount 1 ? month : “0” + month) + “/” + date.getDate() + “/” + date.getFullYear();
    }

    }]
    });
    }
    });
    return dfd.promise();
    }

    //Step 4: Repetative call to getJSONDataFromUrl() to get Ajax Json object.
    function getJSONDataFromUrl(endpoint) {
    return jQuery.ajax({
    url: endpoint,
    method: “GET”,
    headers: {
    “Accept”: “application/json; odata=verbose”,
    “Content-Type”: “application/json; odata=verbose”
    }
    });
    }

    1. Thank you, Keshav for your comment. Check updated code with comments. Hope it solves your problem.

      $(document).ready(function () {
      loadMyItems();
      });

      function loadMyItems() {
      var siteurl = _spPageContextInfo.webAbsoluteUrl; //CHANGE siteAbsoluteUrl TO webAbsoluteUrl
      var RestUrl = siteurl + “/_api/web/lists/getbytitle(‘BP_EDP_GDMP_RELATIONSHIPLIST’)/items?$select=ParentDocName,ChildDocNames,ParentDocId,ParentListName,Modified&$top=5000″;
      var ItemCount = ”;

      $.ajax({
      url: siteurl + “/_api/web/lists/getbytitle(‘BP_EDP_GDMP_RELATIONSHIPLIST’)/ItemCount”,
      method: “GET”,
      async: false,
      headers: { “Accept”: “application/json; odata=verbose” },
      success: function (data) {
      ItemCount = data.d.ItemCount;
      },
      error: function (data) {
      console.log(data);
      }
      });
      var date = new Date();//GET DATE FROM DATE OBJECTS
      console.log( date.getMonth()+1+”/”+date.getDate() + “/” + date.getFullYear()); // Get full date format
      }

      1. Thanks.
        One more thing: The processList function re-initializes the datatables and throwing the following error: DataTables warning: table id=table_id – Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">