0

I managed to access the fields "EnableVersioning", "EnableMajorVersions" etc. to check whether my sharepoint lists have versioning enabled.

However, I didn't find any XML element that controls the number of major versions to keep.

Thank you!

0

The SPList.MajorVersionLimit and SPList.MajorWithMinorVersionsLimit is not exposed in CSOM\JSOM\REST SharePoint 2013 interfaces.

  • even though client APIs do not expose the same set of properties as SSOM, there is an alternative approach to retrieve those properties as demonstrated in my answer – Vadim Gremyachev Feb 12 '15 at 22:19
0

How to retrieve List version related properties using SharePoint REST Interface

Client APIs such as REST/API do not expose the same set of properties as SSOM SPList, for example SPList.MajorVersionLimit is not available in client APIs.

But you could consider the following approach: (*)

  • First step is to retrieve List Schema: /_api/web/lists/getbytitle('list title')?$select=schemaXml
  • Then you could extract List properties from SchemaXml property

(*) Follow An alternative way of getting Client Object properties using SharePoint REST and CSOM APIs for a more details

Example

The following example demonstrates how to retrieve List version related properties:

var webUrl = _spPageContextInfo.webAbsoluteUrl;
getListProperties(webUrl,'Documents').done(function(properties){
     console.log(properties.MajorVersionLimit);
     console.log(properties.MajorWithMinorVersionsLimit);
     console.log(properties.EnableVersioning);
     console.log(properties.EnableMinorVersion);
}); 



function getListProperties(webUrl,listTitle)
{
    var endpointUrl = webUrl + "/_api/web/lists/getbytitle('" + listTitle + "')?$select=schemaXml";
    return getJson(endpointUrl).then(function(data){
             var listProperties = schemaXml2Json(data.d.SchemaXml);
             return listProperties;
           });
}

where

function getJson(url) 
{
    return $.ajax({       
       url: url,   
       type: "GET",  
       contentType: "application/json;odata=verbose",
       headers: { 
          "Accept": "application/json;odata=verbose"
       }
    });
}


function schemaXml2Json(schemaXml)
{ 
    var jsonObject = {};
    var schemaXmlDoc = $.parseXML(schemaXml);
    $(schemaXmlDoc).find('List').each(function() {
      $.each(this.attributes, function(i, attr){
           jsonObject[attr.name] = attr.value;
      });
    });
    return jsonObject;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.