SharePoint Item Version History Webpart

Who, Changed, What, When

Grab it at: github.com/RecursiveKea/ItemVersionHistory

Background

During Migration projects I deal with folders and documents that can have a lot of versions (record being one with 96k versions - we put limits on documents with a lot of versions where appropriate). When doing this I’m verifying that version metadata is brought across as expected. The SharePoint version history UI however has some limitations:

  • Can’t easily see the Folder version history
    Unlike documents you can’t right click on the folder and see its version history image.png

  • (more…)
    Where a lot of changes have occurred a “(more…)” is shown. Unfortunately this is not clickable to see what else had changed (it’s there in the version history, just not easily viewable) image.png

  • Working out what the previous values are
    To do this you have to scroll down and manually work out what the previous versions of this data is

So I thought that it would be a useful to develop a web part to put a UI over this as otherwise I need to continue use PowerShell / JavaScript to review this when data is hidden.

Requirements

Before developing the web part I thought about what would be useful. What I wanted to see was:

  • An augmented view of the default Version History that shows what the old value was
  • Able to see changes by field
  • Able to compare one version to another
  • Able to see hidden, system, and read only fields

Setup

I created Lists and Libraries that had different scenarios (lookup values, term store, and different column types) and then developed a PowerShell script to populate it with some documents to test different use-cases.

REST API Endpoints

In order to access all the SharePoint version history data four different SharePoint REST APIs endpoints are used:

  1. List / Library Fields http://{tenant}.sharepoint.com/sites{sitecollection}/_api/web/GetList(‘{ListRelativeUrl}’)/fields

  2. Item Versions http://{tenant}.sharepoint.com/sites{sitecollection}/_api/web/GetList(‘{ListRelativeUrl}’)/items({ItemId})/versions

  3. Item File Versions http://{tenant}.sharepoint.com/sites{sitecollection}/_api/web/GetFileByServerRelativeUrl (‘{ItemServerRelativeUrl}’)/versions

  4. Item File Current Version http://{tenant}.sharepoint.com/sites{sitecollection}/_api/web/GetFileByServerRelativeUrl (‘{ItemServerRelativeUrl}’)

Input Form

First thing that was developed was the input form:

image.png

The inputs are what are required for the REST API:

  • Site Url
  • List / Library Root Folder Path
  • Item ID

The root folder path is used as it is possible to have two lists with the same display and internal name in the same site (eg "Lists/Example" and "Example" could have the same internal name as "Example"). The root folder path is easier to use than GUID as well.

Display

  • Text: this shows the text value which has been formatted from the properties of the JSON object by the web part code
  • JSON: this shows the value along with extra properties as returned from the REST API versions web service

Comparison Type

  • Text: Sometimes only a text value comparison is required. This comparison takes in to account the "Extra Field Value Properties" checkbox so if this is unchecked the Description for url fields wouldn't be compared for example.
  • JSON: There can be additional properties for a field so this is the most accurate comparison

Options

Hidden, Read Only, and System Fields

Fields can be made hidden, be a read-only and / or a system field so checking these options will force the fields to be shown

Extra Field Value Properties

Some fields have additional properties that would not be shown if just the text value was retrieved. An example of this is the ID in a lookup field.

Exclude Visible Fields

Checking this excludes fields that are visible. These will primarily be user created fields.

View

By Version

This was the first view I developed and where the bulk of the work was done. For this I replicated the OOTB with the addition of showing all fields as well as showing the old value (hovering shows what versions the old value was for).

ByVersion.gif

By Field

This view shows changes by field and what versions they were for. Depending on what options are selected icons will show if the field is Read Only, Hidden, and / or a system field.

image.png

image.png

Compare Specific Versions

This view allows the comparison of metadata between two selected versions: Compare Specific Version.gif

Wrap Up

I developed this web part to solve some of my use-cases so has elements that might not be useful to everyone. It's provided as-is so feel free to grab the code and use the web part / improve upon it (let me know what changes you make in the comments 😀)