I have added a button to trigger the following JS code to display the versioning history for a list item.

<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',

The code is working well on a SharePoint list page, but what I did is to add the list view webpart to a web part page and then added the button/code. It is strange that the code is working fine when I saved even checked in the page, but it is not working after I published the page. The issue is that, even when I selected an item, when i pushed the button I got the message saying that "Please select one row" as if I didn't select any rows. the following is the message shown in the console. enter image description here

Please kindly give me a clue.


Sometimes after publishing the sequence of JS files loaded to the page may change. In your situation first of all I would catch that exception and look at the stack trace. Most probably it’ll give you the reason.

| improve this answer | |

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.