SharePoint Online: Format Calculated Column as Hyperlink

Requirement: Format Calculated Column markup as Hyperlink.

How to Format Calculated Column as Link using HTML Markup?
Using calculated column formulas to frame hyperlink and setting the column type to "Number" renders the column markup as HTML. E.g. I've used this formula to link project documents with Projects list.
=CONCATENATE("<a href='https://crescent.sharepoint.com/sites/projects/documents/'",[ProjectID],">",[Project Name],"</a>")
convert calculated column to hyperlink in sharepoint online

Well, not anymore in SharePoint Online as per the Microsoft announcement Handling HTML markup in SharePoint calculated fields. SharePoint Online renders HTML markup as text instead of HTML!
sharepoint online render calculated column markup as html


So, How to render Calculated column as HTML markups in SharePoint Online? Here is how:
  1. Make sure the list is in New experience, Format the calculated column
    format calculated column as html in sharepoint online
  2. Use this JSON to format the column markup as HTML.
{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "a",
   "txtContent": "Project Documents",
   "attributes": {
      "target": "_blank",
      "href": "='http://crescent.sharepoint.com/sites/projects/' + @currentField"
   }
}
Similarly, you can refer any other fields in the list in JSON as:
"href": "='http://crescent.sharepoint.com/sites/projects/' + [$Project_x0020_Name]"

This JSON renders the text as HTML markup
sharepoint online render calculated column as html

Here is the Microsoft documentation on column formatting: https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting

How about SharePoint 2016/2019 On-Premises? While the above steps works for SharePoint On-premises, You can configure it at web application level settings using PowerShell.
$WebApp = Get-SPWebApplication http://YOUR-web-app-url
$WebApp.CustomMarkupInCalculatedFieldDisabled=$False
$WebApp.update()
SharePoint Online: Format Calculated Column as Hyperlink SharePoint Online: Format Calculated Column as Hyperlink Reviewed by Salaudeen Rajack on January 27, 2019 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.