none
Any Rest API available for Version history of List item fileds RRS feed

  • Question

  • HI,  

    I have a SharePoint 2013 List with versioning enabled. I need to to get SPListItem versions list via REST. I can get SPListItem by that request: 

    https://siteurl/Functions/ISandIT/ISTeamsite/_api/web/lists/getbytitle(%27Projects%27)/items(22) 

    But I can't find version history of one field in response.

    how to retrieve all versions of this item. Is it possible?

    Thanks in advance for support. 

    Wednesday, August 2, 2017 1:53 PM

Answers

  • Hi,

    You could try to get item field version history from Versions.aspx.

    function getListItemByVersionPage(listWebUrl, listId, listItemId, fieldName) {
    
                var glibvpdef = new jQuery.Deferred();
    
                var versionsUrl = listWebUrl + '/_layouts/versions.aspx?list=' + listId + '&ID=' + listItemId;
    
                jQuery.get(versionsUrl)
                 .done(function (data) {
    
                     var entries = [];
                     var versionList = $(data).find('table.ms-settingsframe');
                     if (typeof (versionList) !== typeof (undefined) && versionList !== null) {
    
                         versionList.find('tbody > tr').each(function (i, trval) {
                             // pulls every 2 rows
                             if (i > 0 && (i - 1) % 2 == 0) {
                                 try {
                                     var verRow = $(this); //get version row
                                     var versionLabel = verRow.find('td:first').html().trim();
                                     var versionDateElement = verRow.find('table[ctxname=\"ctxVer\"] a'); // Date for modification
                                     var versionUserElement = verRow.find('.ms-imnSpan a:nth-child(2)'); // User for Modification
                                     if (versionLabel !== ""
                                         && (versionDateElement !== null && versionDateElement.length > 0)
                                         && (versionUserElement !== null && versionUserElement.length > 0)) {
                                         var versionDate = versionDateElement.html().trim();
                                         var versionUser = versionUserElement.html().trim();
    
                                         var propsRow = verRow.next(); //get properties row
                                         var properties = propsRow.find("table[role=\"presentation\"] tr").map(function (index, val) {
    
                                             var trproperty = jQuery(val);
                                             if (val.id.indexOf(fieldName) !== -1) {
                                                 var entryProperties = {
                                                     id: val.id,
                                                     title: trproperty.find("td:first").html().trim(),
                                                     FieldValue: trproperty.find("td:nth-child(2)").html().trim()
                                                 };
                                                 return (entryProperties);
                                             }
                                         });
                                         var entry = {
                                             Label: versionLabel,
                                             Modified: versionDate,
                                             Editor: versionUser,
                                             vprops: properties
                                         };
                                         entries.push(entry);
                                     }
                                 } catch (error) {
                                     console.log("parse error " + error.message);
                                 }
                             }
                         });
                     }
                     glibvpdef.resolve(entries);
                 })
                .fail(function (sender, args) {
                    glibvpdef.reject(sender, args);
                });
    
                return glibvpdef.promise();
            }

    You could check below link for details.

    https://github.com/pinch-perfect/development-samples/blob/master/Sample06/AppFiles/SiteAssets/js/SampleVersionDisp.js

     

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, August 3, 2017 3:12 AM

All replies

  • Hi,

    You could try to get item field version history from Versions.aspx.

    function getListItemByVersionPage(listWebUrl, listId, listItemId, fieldName) {
    
                var glibvpdef = new jQuery.Deferred();
    
                var versionsUrl = listWebUrl + '/_layouts/versions.aspx?list=' + listId + '&ID=' + listItemId;
    
                jQuery.get(versionsUrl)
                 .done(function (data) {
    
                     var entries = [];
                     var versionList = $(data).find('table.ms-settingsframe');
                     if (typeof (versionList) !== typeof (undefined) && versionList !== null) {
    
                         versionList.find('tbody > tr').each(function (i, trval) {
                             // pulls every 2 rows
                             if (i > 0 && (i - 1) % 2 == 0) {
                                 try {
                                     var verRow = $(this); //get version row
                                     var versionLabel = verRow.find('td:first').html().trim();
                                     var versionDateElement = verRow.find('table[ctxname=\"ctxVer\"] a'); // Date for modification
                                     var versionUserElement = verRow.find('.ms-imnSpan a:nth-child(2)'); // User for Modification
                                     if (versionLabel !== ""
                                         && (versionDateElement !== null && versionDateElement.length > 0)
                                         && (versionUserElement !== null && versionUserElement.length > 0)) {
                                         var versionDate = versionDateElement.html().trim();
                                         var versionUser = versionUserElement.html().trim();
    
                                         var propsRow = verRow.next(); //get properties row
                                         var properties = propsRow.find("table[role=\"presentation\"] tr").map(function (index, val) {
    
                                             var trproperty = jQuery(val);
                                             if (val.id.indexOf(fieldName) !== -1) {
                                                 var entryProperties = {
                                                     id: val.id,
                                                     title: trproperty.find("td:first").html().trim(),
                                                     FieldValue: trproperty.find("td:nth-child(2)").html().trim()
                                                 };
                                                 return (entryProperties);
                                             }
                                         });
                                         var entry = {
                                             Label: versionLabel,
                                             Modified: versionDate,
                                             Editor: versionUser,
                                             vprops: properties
                                         };
                                         entries.push(entry);
                                     }
                                 } catch (error) {
                                     console.log("parse error " + error.message);
                                 }
                             }
                         });
                     }
                     glibvpdef.resolve(entries);
                 })
                .fail(function (sender, args) {
                    glibvpdef.reject(sender, args);
                });
    
                return glibvpdef.promise();
            }

    You could check below link for details.

    https://github.com/pinch-perfect/development-samples/blob/master/Sample06/AppFiles/SiteAssets/js/SampleVersionDisp.js

     

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, August 3, 2017 3:12 AM
  • Thank a lot for your quick help.

    This code works for me and saves time..


     
    Thursday, August 3, 2017 9:51 AM
  • Hi,

    You could try to get item field version history from Versions.aspx.

    function getListItemByVersionPage(listWebUrl, listId, listItemId, fieldName) {
    
                var glibvpdef = new jQuery.Deferred();
    
                var versionsUrl = listWebUrl + '/_layouts/versions.aspx?list=' + listId + '&ID=' + listItemId;
    
                jQuery.get(versionsUrl)
                 .done(function (data) {
    
                     var entries = [];
                     var versionList = $(data).find('table.ms-settingsframe');
                     if (typeof (versionList) !== typeof (undefined) && versionList !== null) {
    
                         versionList.find('tbody > tr').each(function (i, trval) {
                             // pulls every 2 rows
                             if (i > 0 && (i - 1) % 2 == 0) {
                                 try {
                                     var verRow = $(this); //get version row
                                     var versionLabel = verRow.find('td:first').html().trim();
                                     var versionDateElement = verRow.find('table[ctxname=\"ctxVer\"] a'); // Date for modification
                                     var versionUserElement = verRow.find('.ms-imnSpan a:nth-child(2)'); // User for Modification
                                     if (versionLabel !== ""
                                         && (versionDateElement !== null && versionDateElement.length > 0)
                                         && (versionUserElement !== null && versionUserElement.length > 0)) {
                                         var versionDate = versionDateElement.html().trim();
                                         var versionUser = versionUserElement.html().trim();
    
                                         var propsRow = verRow.next(); //get properties row
                                         var properties = propsRow.find("table[role=\"presentation\"] tr").map(function (index, val) {
    
                                             var trproperty = jQuery(val);
                                             if (val.id.indexOf(fieldName) !== -1) {
                                                 var entryProperties = {
                                                     id: val.id,
                                                     title: trproperty.find("td:first").html().trim(),
                                                     FieldValue: trproperty.find("td:nth-child(2)").html().trim()
                                                 };
                                                 return (entryProperties);
                                             }
                                         });
                                         var entry = {
                                             Label: versionLabel,
                                             Modified: versionDate,
                                             Editor: versionUser,
                                             vprops: properties
                                         };
                                         entries.push(entry);
                                     }
                                 } catch (error) {
                                     console.log("parse error " + error.message);
                                 }
                             }
                         });
                     }
                     glibvpdef.resolve(entries);
                 })
                .fail(function (sender, args) {
                    glibvpdef.reject(sender, args);
                });
    
                return glibvpdef.promise();
            }

    You could check below link for details.

    https://github.com/pinch-perfect/development-samples/blob/master/Sample06/AppFiles/SiteAssets/js/SampleVersionDisp.js

     

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thank a lot for your quick help.

    This code works for me and saves time..


    Thursday, August 3, 2017 9:52 AM