1

I want to fetch Note Type field version history from SharePoint Hosted App page.

I have tried GetVertinCollection() method /_vti_bin/lists.asmx but unable to fetch item field version history from SharePoint Hosted App.

  • Are you asking how to get the version history of a particular field? Do you mean an appended Note field? You want to get all the appended notes? – Submits Dec 4 '15 at 14:56
0

If I understand your question correctly, you're trying to get all historic values of a multi-line text field.

The SPServices library makes this quite easy.

$scope.getFieldHistory = function (itemId, fieldName, field) {
            $().SPServices({
                operation: "GetList",
                listName: "Your list name",
                async: false,
                completefunc: function (xData, Status) {
                    var xmlDoc = $.parseXML(xData.responseText);
                    $xml = $(xmlDoc);
                    var list = $xml.find("GetListResult > List");
                    var id = list.attr("ID");

                    $().SPServices({
                        operation: "GetVersionCollection",
                        strlistID: id,
                        strlistItemID: itemId,
                        strFieldName: fieldName,
                        completefunc: function (xData, Status) {
                            var xmlDoc = $.parseXML(xData.responseText);
                            $xml = $(xmlDoc);
                            field.history = [];
                            var values = $xml.find("Versions > Version").each(function () {
                                var version = {};
                                version.value = $(this).attr(fieldName);
                                var rawDate = moment($(this).attr("Modified")).local();
                                version.editDate = rawDate.format("MM/DD/YYYY hh:mm A");
                                var rawEditor = $(this).attr("Editor");
                                version.editor = rawEditor.split("#,#")[1];
                                field.history.push(version);

                            });
                        }
                    });
                }
            });
        };

Source

  • Will this work from App? I mean will it work cross-domain if data has to be fetched from host web? – Prakash - Crow Canyon Dec 7 '15 at 6:45
  • Sorry I don't know, never tried it myself. – Submits Dec 7 '15 at 8:54
1

For getting item's version you do not need any extra hassle. When you request for some items to SP, it returns version along with other data. For example, you have made a GET request to the following URL

_api/web/lists/GetByTitle('List Name')/Items

Now in the response, find __metadata.etag. The value of __metadata.etag is your item's version.

{
  "d": {
    "results": [
      {
        "__metadata": {
          "id": "cf7b1e7a-2103-428a-8e97-7e028ffc9e6a",
          "uri": "https://xxx.sharepoint.com/_api/Web/Lists(guid'233ae45e-f581-4420-b069-b7a74d368b13')/Items(1)",
          "etag": "\"6\"",
          "type": "SP.Data.XXXListItem"
        },
        "Title": "Developer Team"
      }
    ]
  }
}
  • thanks for the reply. __metadata.etag just give you the latest vesion number But I want to fetch all the versions details. Please assist me. – Vivek Dec 4 '15 at 14:31
  • get all versions details using rest api seems difficult! Can you add more details in your question? – Atish Dipongkor - MVP Dec 4 '15 at 14:41

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.