“Is there any way to modify the JSON on SharePoint column to hide the “Open” link if there’s no underlying hyperlink?”
“I have a list with links to documents, but there isn’t always a link because there isn’t always a document yet. I don’t want people getting frustrated with dead links.”
When using JSON to format a hyperlink, e.g. to replace Calculated column with hyperlink, you might have some items where the link is empty. In that case you’ll end up with the description text, but no link on the background. Text that look like a link, but leads nowhere. How can you hide this fields and keep only the exiting ones?
Add “style” to the JSON
You can extend the JSON column formatting by adding “style” attribute with an ‘if condition’. If the column with link is empty, apply style “display: none” to hide the column. Otherwise use “display: inherit” to show the link.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "a",
"txtContent": "Open",
"attributes": {
"target": "_blank",
"href": "@currentField"
},
"style": {
"display": "=if(@currentField == '', 'none', 'inherit')"
}
}
The piece of code above will display text “Open” only if the current field is not empty. And you can use not only the current field, but also any other column referenced by [$columName] in the condition.
Is there a way to change the color of the link using JSON?
Hello Richard,”
yes, you can add “style” property in the JSON as shown in this article (in a more complicated way): https://tomriha.com/format-results-of-date-calculation-in-sharepoint-column/.
“style”: {
“color”: “
}
I tried this Json script below to try to make show the link as an SDS on a column but is still showing the entire link
what could be the problem
{
“$schema”: “https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json”,
“elmType”: “a”,
“txtContent”: “SDS”,
“attributes”: {
“target”: “_blank”,
“href”: “@currentField” }
}
Hello Kundani,
the JSON looks fine, is it applied on the column? Didn’t you maybe switch a view?