SOLVED

SharePoint Online JSON Hyperlink Column Formatting - If empty

New Contributor

I am trying to make a hyperlink column to appear "NA" if empty but if a hyperlink is inputted to show as a clickable "View MSA".

I am able to achieve the latter as a clickable link but can't seem to get the if empty/blank working using IF statement.

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "attributes": {
    "href": "@currentField",
    "target": "_blank"
  },
  "txtContent": "View MSA"
}

 

 

 

2022-09-14_9-07-28.png

 

 

Any help is appreciated. 

 

5 Replies
best response confirmed by Harry_Kane (New Contributor)
Solution

@Harry_Kane 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "attributes": {
    "href": "@currentField",
    "target": "_blank"
  },
  "txtContent": "=if(@currentField == '', 'NA','View MSA')"
}

 

Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

Thank you. I see where I went wrong.

@Harry_Kane Try using this JSON: 

 

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "children": [
        {
            "elmType": "span",
            "txtContent": "NA",
            "style": {
                "display": "=if(@currentField, 'none', 'block')"
            }
        },
        {
            "elmType": "a",
            "attributes": {
                "href": "@currentField",
                "target": "_blank"
            },
            "txtContent": "View MSA",
            "style": {
                "display": "=if(@currentField, 'block', 'none')"
            }
        }
    ]
}

 

Output

ganeshsanap_0-1663165647302.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.

@ganeshsanap this is great . You got the format I wanted.

 

Thank you.

@batvan276 You are welcome, glad it helped you and you got the results you were looking for!


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.