i'm looking for a way to make the showing SharePoint 2013 list item version history more intuitive, and eventually i have found the JS code below; however, when i added the code to a SP 2013 list, it is not working. Please kindly advise how to implement the code.

<script type="text/javascript">
var listItem;
var list;
var title;
var clientContext;
var item1;
var value;
var source;
var weburl;
var currentListGUID;

function getSetListItem()
    clientContext = SP.ClientContext.get_current();
    if (clientContext != undefined && clientContext != null)
        currentListGUID = SP.ListOperation.Selection.getSelectedList();
        if(currentListGUID === "undefined" || currentListGUID === null)
            alert('Please select one row');
            var webSite = clientContext.get_web();
            var ctx = GetCurrentCtx();
            title =ctx.ListTitle;
            list = webSite.get_lists().getByTitle(title);
            var selectedItems = SP.ListOperation.Selection.getSelectedItems(clientContext);
            {alert('Please select only one row');}
                for (var item in selectedItems)
                listItem = list.getItemById(item1);
                clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess),
                Function.createDelegate(this, this.OnLoadFailed));

function OnLoadSuccess(sender, args)
    value = this.listItem.get_item("FileLeafRef");

function ShowDialog()
    var options =
        autoSize: true,
        allowMaximize: true,
        title: 'Version History',
        showClose: true,
        url:weburl+'_layouts/15/Versions.aspx?list=' + currentListGUID + '&ID='+item1+'&Source='+weburl+'/Lists/'+title+'/AllItems.aspx',

<input id="btnGetSetListItem" onclick="getSetListItem()" type="button" value="Version History" />
  • Did you add this script to a content editor web part or to a script editor web part? If you look at your browser's console, there must be some JS errors showing up? – moe Jan 8 '18 at 6:12

I think the problem is with URL parameter in ShowDialog() it should be url:weburl+'/_layouts/15/Versions.aspx.... you have missed the slash before _layouts/

the weburl is a server relative URL ending without '/' you have to add it while making up dialog URL

  • Hi Akshay, I will appreciate it very much if you can help me on one more issue. I inserted the list viewer webpart to a publishing page, and then added the JS code. The code is working fine when I saved or even checked-in the page, but it is no longer working when I published the page. The issue is that, even when I selected an item, but got the message saying "Please select one row" when I pushed the button, as if I didn't select any items. – T Zhang Jan 19 '18 at 3:14

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.