1

I have a Hyperlink column in my list which I want to apply some custom formatting. the column is not Required, meaning the field might be blank on some rows.

How can I check if the field is blank, and thereby skip the whole rendering in the JSON formatting?

1 Answer 1

1

The hyperlink field object has the following property which is the Display Text of hyperlink field (with example value):

{
    "desc": "SharePoint Patterns and Practices",
}

To reference the URL value, you need to use @currentField.

For Your case you can use the following JSON to format your hyperlink column:

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
    "elmType": "a",
    "txtContent": "@currentField.desc",
    "attributes": {
         "target": "=if(@currentField!='','_blank','_self')",
         "href": "=if(@currentField!='',@currentField, '')"
    },
    "style": {
         "display": "=if(@currentField!='', 'block','none !important')"
    }
}
3
  • Thank you for your feedback. But I would like to skip the whole rendering. Your example still renders an a tag with a link. How can I tell the script to do NOTHING if the current field is blank or empty? Commented Nov 27, 2018 at 12:57
  • Check the updated answer. In order to do that you need to add Style property to your json to hide the blank links. Commented Nov 27, 2018 at 13:37
  • Welcome. please accept and upvote the answer if it helped you. Commented Nov 28, 2018 at 13:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.