Forum Discussion

Veingro's avatar
Veingro
Copper Contributor
Jan 20, 2021
Solved

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

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...
  • ganeshsanap's avatar
    Jan 20, 2021

    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.

     

Resources