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 Answer 1

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

4
  • For JQuery Commented Oct 13, 2017 at 4:42
  • Can it be possible using jslink? Commented Oct 13, 2017 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. Commented Oct 13, 2017 at 4:53
  • Is it possible to get version history for lookup column in custom list using above jquery refrence? Commented Oct 13, 2017 at 5:46

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.