If somebody like the post and its helpful in your work then, add comments.

Friday, November 6, 2015

SharePoint Office 365 ECMA : Get version of the List Item

Hi,

To get version of the SharePoint list items; there are two option in JavaScript
  1. SPServices
$().SPServices({
            operation: "GetVersionCollection",
            async: false,
            strlistID: "Deviations",
            strlistItemID: DID,
            strFieldName: "PreventionDescription",
            completefunc: function (xData, Status) {
                // alert(xData.responseXML.xml)
                $(xData.responseText).find("Version").each(function () {
                    preventiveListTemp.push({
                        "Description": $(this).attr("PreventionDescription"),
                        "Editor": $(this).attr("Editor").split(",#")[4],
                        "Modified": $(this).attr("Modified"),
                        "Image": "/_layouts/15/userphoto.aspx?size=S&accountname=" + $(this).attr("Editor").split(",#")[3].toLowerCase().replace("@", "%40")
                    });
                });
            }
        });
  1. ECMA 

  • var filePath = '/sites/dk/sites/Departments/qms/Lists/Deviations/' + DID + '_.000'
    var clientContext = new SP.ClientContext;
    //var oList = clientContext.get_web().get_lists().getByTitle('Deviations');
    var web = clientContext.get_web();
    var listItemInfo = web.getFileByServerRelativeUrl(filePath);
    var listItemFields = listItemInfo.get_listItemAllFields();
    clientContext.load(web);
    clientContext.load(listItemInfo);
    clientContext.load(listItemFields);
    clientContext.executeQueryAsync(function (sender, args) {
        var fileVersions = listItemInfo.get_versions();
        clientContext.load(fileVersions);
        clientContext.executeQueryAsync(function (sender, args) {
            var fieldEnumerator = fileVersions.getEnumerator();
            while (fieldEnumerator.moveNext()) {
                var oListItemVersion = fieldEnumerator.get_current();

                // preventiveListTemp.push({

                // });

            }

        }, onQueryFailed);

    }, onQueryFailed);