1

I'm new to JSON column formatting and fairly sure this has been asked before or at least covered, but I'm trying to find a way to highlight empty fields in the SharePoint column (hyperlink) to display a yellow or red background with possibly some text 'Link Required'.

Is there a simple way to do this in the JSON formatting? i.e. IF empty show text 'Link Required' plus a red background ELSE show value in the column.

1 Answer 1

1

This is possible using SharePoint JSON column formatting. Try using below JSON on your hyperlink column:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "div",
      "txtContent": "Link Required",
      "style": {
        "background-color": "yellow",
        "display": "=if(@currentField, 'none', 'block')",
        "padding": "5px"
      }
    },
    {
      "elmType": "a",
      "txtContent": "@currentField.desc",
      "attributes": {
        "target": "_blank",
        "href": "@currentField"
      },
      "style": {
        "display": "=if(@currentField, 'block', 'none')"
      }
    }
  ]
}

Output:

enter image description here

You can modify this JSON as per your requirements to change the background color from yellow to red OR to change any other styling properties.

Documentation: Use column formatting to customize SharePoint

1
  • 1
    That's great, works perfectly. Thanks for the pointing me in the right direction!
    – user102444
    Commented Feb 16, 2022 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.