JQuery to Loop Through List's Item Version History. Extract Version No., Modified (date), and Modified By (person/user)

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/279379

Question

I am trying to find a method to open every list Item's version history, get the Version No., Modified dateTime, and Modified By, and then aggregate it into a master csv.

I need to aggregate every version for every item into one list. It will be a very large output, clearly.

I imagine it would use this url and advance/loop to the next Item ID as the suffix on this url:

https://site/list/_layouts/15/versions.aspx?list=[listidNumber]&ID=133

Possible? Looking for ideas as well. I understand JQuery and can tweak it, but cannot write it cold.

Many thanks-

Was it helpful?

Solution

Please check this post: How to get version history of item using REST

It describes the necessary steps to load version history using SharePoint REST API. I hope it will help you to fetch all the data you want by adding them in the $select query option.

For SharePoint Online:

$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + 
        "/_api/web/Lists/getbytitle('JobTitles')/items(1)/versions?$select=Title,VersionLabel",
    async: false,
    headers: {
        'accept': 'application/json;odata=nometadata'
    },
    complete: function(request) {
        console.log("CurrentUser: " + JSON.stringify(request, null, 4));
    },
    error: function(request) {
        console.log(JSON.stringify(request, null, 4));
    }
});

For SharePoint 2013 they have prescribed to use the following API endpoint:

https://{site_url}/_api/web/GetFileByServerRelativeUrl('/sites/siteName/Lists/listName/{itemID}_.000')/Versions
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top