SOLVED

Conditional column formatting to create hyperlink to different sites based on item value

%3CLINGO-SUB%20id%3D%22lingo-sub-2079060%22%20slang%3D%22en-US%22%3EConditional%20column%20formatting%20to%20create%20hyperlink%20to%20different%20sites%20based%20on%20item%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2079060%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EAs%20in%20the%20subject-%20I%20would%20like%20to%20create%20hyperlinks%20to%20different%20sites%20under%20one%20column%20depending%20on%20the%20text%20value%20for%20the%20item%20on%20the%20list%2Flibrary%20under%20that%20column.%20So%20for%20example%20item%201%20is%20having%20value%20%22X%22%20under%20column%20%22Y%22%20and%20I%20want%20%22X%22%20to%20be%20hyperlinked%20to%20site%20%22A%22%2C%20if%20the%20value%20of%20the%20item%20is%20%22Z%22%20I%20want%20hyperlink%20to%20site%20%22Z%22%20etc.%20Would%20someone%20be%20so%20nice%20and%20give%20an%20example%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2079060%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDocument%20Library%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor

Hello, 

As in the subject- I would like to create hyperlinks to different sites under one column depending on the text value for the item on the list/library under that column. So for example item 1 is having value "X" under column "Y" and I want "X" to be hyperlinked to site "A", if the value of the item is "Z" I want hyperlink to site "Z" etc. Would someone be so nice and give an example?

1 Reply
best response confirmed by Veingro (New Contributor)
Solution

@Veingro 

Based on what I understood from your question, you need to use JSON in below format:

 

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "a",
    "txtContent": "@currentField",
    "attributes": {
        "href": "=if(@currentField == 'X', 'https://tenant.sharepoint.com/sites/A', if(@currentField == 'Z', 'https://tenant.sharepoint.com/sites/Z', 'https://tenant.sharepoint.com/sites/default'))",
        "target": "_blank"
    }
}

 

Add this code to column "Y" by selecting "Format this column" settings.

DocumentationUse column formatting to customize SharePoint 


Please click Mark as Best Response if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.