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.
- <!-- Style required for HTML Snippet -->
- <style type="text/css">
- .lst-table th{ background-color:#ddd; border:2px solid #fff; text-align:left}
- .lst-table td{ background-color:#eee; border:2px solid #fff;}
- .web-heading{ padding:2px;}
- </style>
- <!--Include jQuery library to perform dynamic html dom manipulation -->
- <script type="text/javascript" src="/siteassets/jquery.js"></script>
- <div>
- <h2 class="web-heading">List with versioning enabled</h2>
- </div>
- <table width="100%" cellpadding="10" cellspacing="2" id="lstTable" class="lst-table">
- <thead>
- <tr>
- <th></th>
- <th>List Title</th>
- <th>Id</th>
- <th>Version enabled</th>
- <th>Items Count</th>
- </tr>
- </thead>
- <tbody></tbody>
- </table>
- <!-- Script snippet to perform the required operation-->
- <!-- Following script returns the collection of lists without versioing -->
- <script type="text/javascript">
- function getLists() {
- var siteurl = _spPageContextInfo.webAbsoluteUrl;
- $.ajax({
- url: siteurl + "/_api/web/lists?$filter=EnableVersioning%20eq%20true",
- method: "GET",
- headers: { "Accept": "application/json; odata=verbose" },
- success: function (data) {
-
- onSucceed(data);
- },
- error: function (data) {
- onFailure(data);
- }
- });
- }
- function onSucceed(data){
-
- var filterLists = data.d.results;
- for(i=0; i
- <filterLists.length;i++){
-
- var lstimage = "
- <img src='"+filterLists[i].ImageUrl+"'/>";
- var trow = "
- <tr>
- <td>"+lstimage+"</td>
- <td>"+filterLists[i].Title+"</td>
- <td>"+filterLists[i].Id+"</td>
- <td>"+filterLists[i].EnableVersioning+"</td>
- <td>"+filterLists[i].ItemCount+"</td>
- </tr>";
-
- $("#lstTable tbody").append(trow);
- }
- }
- function onFailure(error){
- alert(error);
- }
- function injectMethod(){
- getLists();
- }
- injectMethod();
-
- </script>
OutputHow to retrieve the Lists without versioningThe following snippet returns the collection of lists that are not version enabled.
- <!-- Style required for HTML Snippet -->
- <style type="text/css">
- .lst-table th{ background-color:#ddd; border:2px solid #fff; text-align:left}
- .lst-table td{ background-color:#eee; border:2px solid #fff;}
- .web-heading{ padding:2px;}
- </style>
- <!--Include jQuery library to perform dynamic html dom manipulation -->
- <script type="text/javascript" src="/siteassets/jquery.js"></script>
- <div>
- <h2 class="web-heading">List without versioning</h2>
- </div>
- <table width="100%" cellpadding="10" cellspacing="2" id="lstTable" class="lst-table">
- <thead>
- <tr>
- <th></th>
- <th>List Title</th>
- <th>Id</th>
- <th>Version enabled</th>
- <th>Items Count</th>
- </tr>
- </thead>
- <tbody></tbody>
- </table>
- <!-- Script snippet to perform the required operation-->
- <!-- Following script returns the collection of lists without versioing -->
- <script type="text/javascript">
- function getLists() {
- var siteurl = _spPageContextInfo.webAbsoluteUrl;
- $.ajax({
- url: siteurl + "/_api/web/lists?$filter=EnableVersioning%20eq%20false",
- method: "GET",
- headers: { "Accept": "application/json; odata=verbose" },
- success: function (data) {
-
- onSucceed(data);
- },
- error: function (data) {
- onFailure(data);
- }
- });
- }
- function onSucceed(data){
-
- var filterLists = data.d.results;
- for(i=0; i
- <filterLists.length;i++){
-
- var lstimage = "
- <img src='"+filterLists[i].ImageUrl+"'/>";
- var trow = "
- <tr>
- <td>"+lstimage+"</td>
- <td>"+filterLists[i].Title+"</td>
- <td>"+filterLists[i].Id+"</td>
- <td>"+filterLists[i].EnableVersioning+"</td>
- <td>"+filterLists[i].ItemCount+"</td>
- </tr>";
-
- $("#lstTable tbody").append(trow);
- }
- }
- function onFailure(error){
- alert(error);
- }
- function injectMethod(){
- getLists();
- }
- injectMethod();
-
- </script>
Output