Dynamically change text column to hyperlink in SharePoint Online list

Convert a single line of text column to hyperlink using SharePoint column formatting

No comments

 8,269 total views,  20 views today

In this article, we will learn about how to covert Single Line of Text Column to Hyperlink using Column Formatting in SharePoint Online list. Many times, in the SharePoint Online list we store the site URL (hyperlink) inside the single textbox column where the user feels hurdle to manage the link, so for the ease of the user, we need to convert the text type column value to hyperlink.

SharePoint column formatting display a single line of text as hyperlink

Let’s look at the below example where we have a test list with the two columns “Title” and “Site URL” (Single Line of Text Type).

Hyperlink URL in Single Line Text column in SharePoint Online list
Hyperlink URL in Single Line Text column in SharePoint Online list

If we closely, look at the value of the Site URL we could see it is – “www.google.com” which text type.

Now let’s convert this text value to the hyperlink.

Click on the “Site URL” column dropdown list -> Column Settings – > Format this column

Format SharePoint Online text column to hyperlink column

Format SharePoint Online text column to hyperlink column then click on the “Advanced mode” link from the right-side panel.

Advanced mode in SharePoint Online format columns
The advanced mode in SharePoint Online format columns

Then replace the out of the box JSON text with the below custom JSON value:

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "a",
"attributes": {
"href": "@currentField",
"target": "_blank"
},
"txtContent": "@currentField"
}
Replace the out of the box JSON with the custom JSON text
Replace the out of the box JSON with the custom JSON text
Using Custom JSON formatting convert text column to hyperlink in SharePoint Online
Using Custom JSON formatting convert text column to hyperlink in SharePoint Online

Once we apply the custom JSON and click on the preview button, immediately we can see that the value of the “Site URL” column has been changed from the text to hyperlink.

Now click on the “Save” button.

Now let’s dynamically change the value hyperlink display value, for this example, here it should display “Google” as a hyperlink wherein the background this will link will be pointing to “www. google.com”.

The “txtContent“: “[$Title]” paramter is handling this job.

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "a",
"attributes": {
"href": "@currentField",
"target": "_blank"
},
"txtContent": "[$Title]"
}
Dynamically change text column to hyperlink in SharePoint Online list
Dynamically change text column to hyperlink in SharePoint Online list

Click on the “Save” button.

Note:

  • Due to security reasons, this formatting can be done with SharePoint Online URL, so, when you are trying you could try with some test SharePoint site URL.
  • In the above code, the “target”: “_blank” parameter indicates that the link should be opened in the new tab of the browser.

Summary:

Thus in this article, we have learned about how to convert the Single Line Text column to hyperlink dynamically in the modern SharePoint Online list.

See Also:

You may also like the below article on modern SharePoint Online:

Buy the premium version of SharePoint Online & Office 365 administration eBook from here:

Buy SharePoint Online & Office 365 Administration eBook