SOLVED

SPO List JSON Formatting - Dynamic Hyperlinks with column if statements

Copper Contributor

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"
            
            }
        }
    ]
}
3 Replies

Hi @Ant__thony 

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

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

best response confirmed by Ant__thony (Copper Contributor)
Solution

@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

ganeshsanap_0-1678175266197.png


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

1 best response

Accepted Solutions
best response confirmed by Ant__thony (Copper Contributor)
Solution

@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

ganeshsanap_0-1678175266197.png


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

View solution in original post