Using the following JavaScript function, I am able to get all versions of a specified list item:

function getListItemVersions(listTitleOrId, listItemId) {
  let context = null;
  let web = null;
  try {
    context = SP.ClientContext.get_current();
    web = context.get_web();
    let filePath = `/Lists/${listTitleOrId}/${listItemId}_.000`;
    let listItemInfo = web.getFileByServerRelativeUrl(filePath);
    let listItemFields = listItemInfo.get_listItemAllFields();
      function (sender, args) {
        let fileVersions = listItemInfo.get_versions();
          function (sender, args) {
            let objlistVersionEnumerator = fileVersions.getEnumerator();
            while (objlistVersionEnumerator.moveNext()) {
              let objCurrentListItemVersion =
          function (sender, args) {
            console.log('Error getting versions from server', sender, args);
      function (sender, args) {
        console.log('Error getting list from server', sender, args);
  } catch(e) {

For example, if I have a list called "Test List" which has an item with an ID of 23, I can call getListItemVersions("Test List", 23) and have all versions of the item logged. The problem is that I'm getting back objects of the type SP.FileVersion, i.e.:

enter image description here

Using the SP.FileVersion returned, how can I get the values of the fields at each version of the list item?

1 Answer 1


While this doesn't necessarily answer my question as asked, I did find an alternate method which allowed me to access all versions of a specific field from a specific list item by, modifying some good code from here.

function getListItemVersions(listWebUrl, listName, listItemId, fieldName,
    onSuccess, onError) {
  var glisoapdef = new jQuery.Deferred();
  var soapHeader = 'http://schemas.microsoft.com/sharepoint/soap/';
  var soapAction = soapHeader + 'GetVersionCollection';
  var soapBody = '<soap:Envelope xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-'+
    'instance\' xmlns:xsd=\'http://www.w3.org/2001/XMLSchema\' xmlns:soap=\'' +
    'http://schemas.xmlsoap.org/soap/envelope/\'><soap:Body>' + 
    '<GetVersionCollection xmlns="' + soapHeader + '"><strlistID>' + listName +
    '</strlistID><strlistItemID>' + listItemId + '</strlistItemID><strFieldName>'+
    fieldName + '</strFieldName></GetVersionCollection></soap:Body></soap:Envelope>';

    url: listWebUrl + '/_vti_bin/lists.asmx',
    type: 'POST',
    async: false,
    beforeSend: function beforeSend(xhr) {
      xhr.setRequestHeader('SOAPAction', soapAction);
    dataType: 'xml',
    data: soapBody,
    contentType: "text/xml;charset='utf-8'",
    complete: function complete(xData, status) {
      var historyOptions = [];
      $(xData.responseText).find('Version').each(function (i) {
        var editorValue = '';
        var editor = $(this).attr('editor').split('#');
        if (editor.length >= 1) {
          editorValue = editor[1];
          var editorLen = editorValue.length;
          if (editorValue.lastIndexOf(',') == editorLen - 1) {
            editorValue = editorValue.substring(0, editorLen - 1);
        editor = editorValue.replace(',,', ',');
          Editor: editor,
          Modified: $(this).attr('Modified'),
          FieldValue: $(this).attr(fieldName)
    error: function error(jqXHR, textStatus, errorThrown) {
      onError(jqXHR, textStatus, errorThrown);
      glisoapdef.reject(jqXHR, textStatus, errorThrown);

You can use it as follows:

getListItemVersions('https://mycompany.sharepoint.com', 'List Name', 2308,
    'Field Name', function(items) {
  // do something with the items

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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