1

I need to display all version using jslink or javascript in custom list. Is it possible to get version history for item in custom list?

enter image description here

1

According to your post, my understanding is that you want to get list item version using JavaScript Client Object Model.

The following code snippet for your reference:

that.getData = function (listName, xmlQuery, contentType, onGetSuccess) {
var objClientCtx = new SP.ClientContext.get_current();
if (objClientCtx) {
    var oWeb = objClientCtx.get_web();
    var oList = oWeb.get_lists().getByTitle(listName);                
    var query = new SP.CamlQuery();
    query.set_viewXml(xmlQuery);
    var objlistItems = oList.getItems(query);
    objClientCtx.load(objlistItems);                
    objClientCtx.executeQueryAsync(function (sender, args) {
        that.DataSet = [];
        var objlistEnumerator = objlistItems.getEnumerator();
        while (objlistEnumerator.moveNext()) {
            var objListItem = objlistEnumerator.get_current();
            var id = objListItem.get_item('ID');
            var filePath = 'your site collection/Lists/your list/'+id+'_.000'
            var web = objClientCtx.get_web();
            var listItemInfo = web.getFileByServerRelativeUrl(filePath)
            var listItemFields = listItemInfo.get_listItemAllFields()
            objClientCtx.load(web);
            objClientCtx.load(listItemInfo);
            objClientCtx.load(listItemFields);
            //objClientCtx.load(versions1);
            objClientCtx.executeQueryAsync(
                function (sender, args) {
                    var fileVersions = listItemInfo.get_versions();
                    objClientCtx.load(fileVersions);
                    objClientCtx.executeQueryAsync(
                        function (sender, args) {
                            var objlistVersionEnumerator = fileVersions.getEnumerator();
                            while (objlistVersionEnumerator.moveNext()) {
                                var objCurrentListItemVersion = objlistVersionEnumerator.get_current();
                                console.log(objCurrentListItemVersion.get_url());
                            }

                        },
                        function (sender, args) {console.log('Error');}
                    )

                }, 
                function (sender, args){
                    console.log('error')
                });                         

        }
        onGetSuccess(that.DataSet);

    }, function (sender, args) {
        that._onGetFail(sender, args);
    });
  }
}

More information is here: How to get all versions of a SharePoint list using JSOM

  • For JQuery – san Oct 13 '17 at 4:42
  • Can it be possible using jslink? – Akshay Oct 13 '17 at 4:47
  • JsLink is only applicable to Views,Content Types,columns and Items not specific to item's version. You can create the list view that only for viewing the items in version wise and then apply the jslink to that view. – san Oct 13 '17 at 4:53
  • Is it possible to get version history for lookup column in custom list using above jquery refrence? – Akshay Oct 13 '17 at 5:46

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.