Get the Lists Based on Version Enabled Using REST

SharePoint 2013 provides the interface called Representable State Transfer (REST) that can access all SharePoint properties and operations that are available in the other SharePoint Client APIs. Other client APIs require the reference of the client libraries or assemblies to be included or called to perform the operation with SharePoint. Unlike other client APIs, we need to make HTTP requests to the appropriate endpoints to access the SharePoint objects (web, lists, list items and so on).

There are some useful reports that are not available in SharePoint OOTB, so here I tried to generate one report to retrieve the version enabled lists and lists without versioning.

The following REST endpoint URL does those operations.

URL Description
/_api/web/lists?$filter=EnableVersioning eq true Returns the version enabled list collection
/_api/web/lists?$filter=EnableVersioning eq false Returns the list collections that are not version enabled

EnableVersioing is the boolean property available in the Lists schema that represents whether the version is enabled in the list or not.

  • EnableVersioing equals True: Version enabled
  • EnabledVersioing equals False: Version not enabled

Using a Content Editor webpart, we can include the sample snippets to the pages in SharePoint to generate a report. Refer to the Gift For Developers From SharePoint to include a snippet to the page.

How to retrieve the Version enabled Lists

The following snippet returns the collection of version-enabled lists.

  1. <!-- Style required for HTML Snippet -->  
  2. <style type="text/css">     
  3. .lst-table th{ background-color:#ddd; border:2px solid #fff; text-align:left}     
  4. .lst-table td{ background-color:#eee; border:2px solid #fff;}     
  5. .web-heading{ padding:2px;}     
  6. </style>  
  7. <!--Include jQuery library to perform dynamic html dom manipulation -->  
  8. <script type="text/javascript" src="/siteassets/jquery.js"></script>  
  9. <div>  
  10.     <h2 class="web-heading">List with versioning enabled</h2>  
  11. </div>  
  12. <table width="100%" cellpadding="10" cellspacing="2" id="lstTable" class="lst-table">  
  13.     <thead>  
  14.         <tr>  
  15.             <th></th>  
  16.             <th>List Title</th>  
  17.             <th>Id</th>  
  18.             <th>Version enabled</th>  
  19.             <th>Items Count</th>  
  20.         </tr>  
  21.     </thead>  
  22.     <tbody></tbody>  
  23. </table>  
  24. <!-- Script snippet to perform the required operation-->  
  25. <!-- Following script returns the collection of lists without versioing -->  
  26. <script type="text/javascript">  
  27. function getLists() {  
  28. var siteurl = _spPageContextInfo.webAbsoluteUrl;  
  29.     $.ajax({  
  30.         url: siteurl + "/_api/web/lists?$filter=EnableVersioning%20eq%20true",  
  31.         method: "GET",  
  32.         headers: { "Accept""application/json; odata=verbose" },  
  33.         success: function (data) {  
  34.             // Returning the results  
  35.             onSucceed(data);  
  36.         },  
  37.         error: function (data) {  
  38.             onFailure(data);  
  39.         }  
  40.     });  
  41. }  
  42. function onSucceed(data){  
  43. //Collection of lists returned as a result  
  44. var filterLists = data.d.results;  
  45.     for(i=0; i  
  46.     <filterLists.length;i++){  
  47.     //Get List Image url  
  48.     var lstimage = "  
  49.         <img src='"+filterLists[i].ImageUrl+"'/>";  
  50.     var trow = "  
  51.         <tr>  
  52.             <td>"+lstimage+"</td>  
  53.             <td>"+filterLists[i].Title+"</td>  
  54.             <td>"+filterLists[i].Id+"</td>  
  55.             <td>"+filterLists[i].EnableVersioning+"</td>  
  56.             <td>"+filterLists[i].ItemCount+"</td>  
  57.         </tr>";  
  58.     //Append each list to the table as a row  
  59.     $("#lstTable tbody").append(trow);  
  60.     }  
  61. }  
  62. function onFailure(error){  
  63.    alert(error);  
  64. }  
  65. function injectMethod(){  
  66.    getLists();  
  67. }  
  68. injectMethod();  
  69.   
  70. </script>  
Output

list with versioning enabled

How to retrieve the Lists without versioning

The following snippet returns the collection of lists that are not version enabled.
  1. <!-- Style required for HTML Snippet -->  
  2. <style type="text/css">     
  3. .lst-table th{ background-color:#ddd; border:2px solid #fff; text-align:left}     
  4. .lst-table td{ background-color:#eee; border:2px solid #fff;}     
  5. .web-heading{ padding:2px;}     
  6. </style>  
  7. <!--Include jQuery library to perform dynamic html dom manipulation -->  
  8. <script type="text/javascript" src="/siteassets/jquery.js"></script>  
  9. <div>  
  10.     <h2 class="web-heading">List without versioning</h2>  
  11. </div>  
  12. <table width="100%" cellpadding="10" cellspacing="2" id="lstTable" class="lst-table">  
  13.     <thead>  
  14.         <tr>  
  15.             <th></th>  
  16.             <th>List Title</th>  
  17.             <th>Id</th>  
  18.             <th>Version enabled</th>  
  19.             <th>Items Count</th>  
  20.         </tr>  
  21.     </thead>  
  22.     <tbody></tbody>  
  23. </table>  
  24. <!-- Script snippet to perform the required operation-->  
  25. <!-- Following script returns the collection of lists without versioing -->  
  26. <script type="text/javascript">  
  27. function getLists() {  
  28. var siteurl = _spPageContextInfo.webAbsoluteUrl;  
  29.     $.ajax({  
  30.         url: siteurl + "/_api/web/lists?$filter=EnableVersioning%20eq%20false",  
  31.         method: "GET",  
  32.         headers: { "Accept""application/json; odata=verbose" },  
  33.         success: function (data) {  
  34.             // Returning the results  
  35.             onSucceed(data);  
  36.         },  
  37.         error: function (data) {  
  38.             onFailure(data);  
  39.         }  
  40.     });  
  41. }  
  42. function onSucceed(data){  
  43. //Collection of lists returned as a result  
  44. var filterLists = data.d.results;  
  45.     for(i=0; i  
  46.     <filterLists.length;i++){  
  47.     //Get List Image url  
  48.     var lstimage = "  
  49.         <img src='"+filterLists[i].ImageUrl+"'/>";  
  50.     var trow = "  
  51.         <tr>  
  52.             <td>"+lstimage+"</td>  
  53.             <td>"+filterLists[i].Title+"</td>  
  54.             <td>"+filterLists[i].Id+"</td>  
  55.             <td>"+filterLists[i].EnableVersioning+"</td>  
  56.             <td>"+filterLists[i].ItemCount+"</td>  
  57.         </tr>";  
  58.     //Append each list to the table as a row  
  59.     $("#lstTable tbody").append(trow);  
  60.     }  
  61. }  
  62. function onFailure(error){  
  63.    alert(error);  
  64. }  
  65. function injectMethod(){  
  66.    getLists();  
  67. }  
  68. injectMethod();  
  69.   
  70. </script>  
Output

list