2

I'm using JSON to format a hyperlink column in SharePoint online. If the column @currentfield isn't filled in, there shouldn't be a link. Can anyone help me?

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
    "target": "_blank",
    "href": "='https://contoso.sharepoint.com/w' + @currentField"

  }
2

You can achieve this using a style tag with a conditional, see below:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
    "target": "_blank",
    "href": "='https://contoso.sharepoint.com/w' + @currentField"
  "style": {
    "display": "=if(@currentField!='', 'block','none !important')",
  }
}

Though personally, I like a good link icon, so I format mine like so:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "a",
      "attributes": {
        "target": "_blank",
        "iconName": "Link",
        "class": "sp-field-quickActions",
        "href": "=if(@currentField!='',@currentField,''"
      },
      "style": {
        "display": "=if(@currentField!='', 'block','none !important')",
        "padding-left": "40px"
      }
    }
  ]
}

Hope that helps!

  • Thanks for your solution! Its working great for me :-) – Andreas Olbricht May 16 at 10:11
1

I did not find the way to format the field as a hyperlink if it is not empty only.

The way I can think of implementing this requirement is to turn the empty field to a link which is used to refresh the page.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
    "target": "=if(@currentField!='','_blank', '_self')",
    "href": "=if(@currentField!='','https://testlz.sharepoint.com/sites/' + @currentField, '')"
  }
}

JSON formatting in SharePoint Online

  • any progress on this? I'm trying to accomplish the same thing with column formatting. – Haymak3r Oct 29 '18 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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