Forum Discussion
Ant__thony
Mar 07, 2023Copper Contributor
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 ...
- Mar 07, 2023
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
Mar 07, 2023Bronze 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