0

I need to get the versions and its changes. It is possible using javascript client object model or REST?

1

First get the list item object and try following:

var id = objListItem.get_item('ID');
var filePath = 'Path to current list/ListName/'+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);

Every list item in sharepoint lists is like url and any list item will be represented as path to site collection/Lists/list name/'+id+'_.000. id represents the current list item id

Get reference to individual list item info with the following code snippet web.getFileByServerRelativeUrl(filePath) and execute the code

objClientCtx.executeQueryAsync(
    function (sender, args) {
        var fileVersions = listItemInfo.get_versions();
        objClientCtx.load(fileVersions);

get_versions() api will give all the versions of the current list item. Execute the query async again after calling the function get_versions().

get_url() will have the information regarding the version history number of the list item

Source

How to get all versions of a SharePoint list using JSOM

  • If my site url is domain.com, and my list is "Roteiros", filePath = ?? – Joao Paulo Mar 9 '15 at 20:21
  • Go to view all site content, click the list and get the URL till http://domain.com/Lists/ListName – Arsalan Adam Khatri Mar 10 '15 at 7:31
  • Hi, when I try to fetch get_createdBy from FileVersion object it returns SP.User object and when I try to fetch user title from SP.User object I get an error that Title is not initialize in the following manner: while (objlistVersionEnumerator.moveNext()) { var vItem = objlistVersionEnumerator.get_current(); vItem.get_createdBy().get_title(); } I even tried to load createdBy but failed. Please help. – Dharam Padia Mar 1 '18 at 7:24
  • @DharamPadia can you try .get_loginName() instead of .get_title() – Arsalan Adam Khatri Mar 1 '18 at 7:36
  • even .get_loginName() is not working. – Dharam Padia Mar 7 '18 at 7:22

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.