Back to column formats
Column formattingSharePoint Online

Published Version

This sample creates a button for opening the currently published version of a document.

Published Version formatting preview
Sample preview · View original image

Copy. Apply. Make it yours.

Get this format

1 definition

Review the requirements below, then paste this JSON into the matching formatting panel. Show me where.

Use your list's internal column names and replace any tenant-specific URLs or flow IDs. Formatting is presentation, not a way to secure data.

Column formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "visibility": "=if([$File_x0020_Type] == '' || [$_UIVersion] < 512, 'hidden', 'visible')"
  },
  "children": [
    {
      "elmType": "div",
      "children": [
        {
          "elmType": "a",
          "attributes": {
            "href": "=if([$_UIVersion] % 512 == 0, [$FileRef], @currentWeb + '/_vti_history/' + 512*floor([$_UIVersion]/512) + substring([$FileRef], indexOf(@currentWeb+'^','^')-indexOf(@currentWeb,'.sharepoint.com')-15, indexOf([$FileRef]+'^','^')))",
            "target": "_blank",
            "class": "ms-fontColor-gray200 ms-bgColor-white ms-fontColor-white--hover ms-bgColor-themePrimary--hover ms-borderColor-themeDark ms-borderColor-themeDark--hover",
            "title": "='Open Version ' + toString(floor([$_UIVersion]/512)) + '.0'"
          },
          "style": {
            "text-decoration": "none",
            "padding": "5px 30px",
            "border-radius": "5px",
            "font-size": "13px",
            "white-space": "nowrap",
            "border-width": "1px",
            "border-style": "solid"
          },
          "txtContent": "='Open Version ' + toString(floor([$_UIVersion]/512)) + '.0'"
        }
      ]
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample creates a button for opening the currently published version of a document. The sample is supposed to be used in a SharePoint Online document library with minor versions enabled. Button is displayed for every document with a published version, i.e., at version at least 1.0. It is linked to the latest published version of the document - for example, if the latest draft of the document is at version 2.8, the button opens version 2.0.

screenshot of the sample

[!NOTE]
The behavior of the button varies in different browsers and for different file types. For Office documents in Microsoft Edge, the button opens the file directly from SharePoint in the installed app. In other browsers, the button usually downloads the document, optionally opening it after download, based on settings.

View requirements

  • This format can be applied to any column type

Sample

Solution Author(s)
generic-published-version.json Miroslav Kačena (@MiroslavKacena)

Version history

Version Date Comments
1.0 October 7, 2024 Initial release

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.


Additional notes

None