1

I am trying to format a column and create a custom hyperlink in a column field based on a specific criteria.

I have three options for this field and I only want to create a link if the field is one specific option. My options are "Available, Not Available, and Limited".

I want SharePoint to create a link to another page when the option is set to "Limited" only.

enter image description here

The code I am working with is below:

{
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
    "target": "_blank",
    "href": "='http://www.google.com/' + ''"
  }

I have tried setting the href to "href": "=if(@currentField=='Limited' + 'http://www.google.com')"

...and several other parameters but it keeps adding links to all fields in the column or just failing completely to add the link.

1 Answer 1

1

Use below JSON code:

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

Microsoft documentation: Use column formatting to customize SharePoint

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.