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? 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. Nov 27, 2018 at 13:37
  • Welcome. please accept and upvote the answer if it helped you. Nov 28, 2018 at 13:10

Your Answer

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

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