Forum Discussion

Ant__thony's avatar
Ant__thony
Copper Contributor
Mar 07, 2023
Solved

SPO List JSON Formatting - Dynamic Hyperlinks with column if statements

I'm attempting to change the hyperlink depending on a choice column "RequestType".  Have been unable to set the url while also adding in a column data. Here is what I have tried.

 

 

First Test

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "a",
    "txtContent": "Net Link",
    "attributes": {
        "href": "=if([$RequestType] = 'Create', 'https://removelink.=' + [$TicketNumber], if([$RequestType] = 'Move', 'https://link/ticketid=' + [$TicketNumber], '<Home Link>'))",
        "target": "_blank"
    }
}

 

Second Test:

 

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "children": [
        {
            "elmType": "a",
            "txtContent": "Link - build",
            "attributes": {
               "href": "=if([$RequestType] = 'Create', 'https://link/ticketid=' + [$TicketNumber]",
               "Target": "_blank"
            }
        },
        {
            "elmType": "a",
             "txtContent": "Link - Transfer",
            "attributes": {
                "href": "=if([$RequestType] = 'Move', 'https://link/ticketid=' + [$MACTicketNumber]",
                "target": "_blank"
            
            }
        }
    ]
}
  • Ant__thony Use JSON formatting in this format: 

     

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "a",
      "txtContent": "Net Link",
      "attributes": {
        "href": "=if([$RequestType] == 'Create', 'https://removelink.=' + [$TicketNumber], if([$RequestType] == 'Move', 'https://link/ticketid=' + [$TicketNumber], 'https://www.google.com/'))",
        "target": "_blank"
      }
    }

     

    Output


    Please click Mark as Best Response & Like 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.

    For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs

  • Ant__thony Use JSON formatting in this format: 

     

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "a",
      "txtContent": "Net Link",
      "attributes": {
        "href": "=if([$RequestType] == 'Create', 'https://removelink.=' + [$TicketNumber], if([$RequestType] == 'Move', 'https://link/ticketid=' + [$TicketNumber], 'https://www.google.com/'))",
        "target": "_blank"
      }
    }

     

    Output


    Please click Mark as Best Response & Like 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.

    For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs

  • SvenSieverding's avatar
    SvenSieverding
    Bronze Contributor

    Hi Ant__thony 

    you need to use "==" in a comparison (https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/formatting-syntax-reference#operators)

    This code works for me

    {
        "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
        "elmType": "a",
        "txtContent": "Net Link",
        "attributes": {
            "href": "=if([$RequestType] == 'Create', 'https://removelink.=' + [$TicketNumber], if([$RequestType] == 'Move', 'https://link/ticketid=' + [$TicketNumber], '<Home Link>'))",
            "target": "_blank"
        }
    }


    (Well... and RequestType and TicketNumber need to be in the view)
     
    Best Regards,
    Sven

Resources