2

I know there are several questions/answers for this, but I still can't seem to get it to work.

Name - Text
URL - Text
Link - Calculated Column Number

enter image description here

Link column

=CONCATENATE("<a href='",URL,"' target='_blank'>",Name,"</a>")

If I add this into the Column Formatting for Link

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
 "elmType": "a",
 "txtContent": "[$Name]",
 "attributes": {
     "target": "_blank",
     "href": "="[$URL]" + [$Name]"
  }
}

When I go back to the list, Link is empty

I thought I had followed all the guides and what not, but... Any thoughts?

2

Try with this json:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "[$InternalNameOfYourNameColumn]",
  "attributes": {
    "target": "_blank",
    "href": "[$URL]"
  }
}

Btw, Name should be reserved name, so the internal name of your Name column is probably different than the display name and you should use that internal name in json formula (just replace InternalNameOfYourNameColumn in my formula with the appropriate value).

4
  • 1
    Got it to work (those weren't the actual field names), but some strange behavior. In my production list, there would be three sets of these and some would work with no space in the field name (PrimaryName) and some would work with a space only (Primary Name). Not sure why, but thanks! Feb 27 '20 at 18:31
  • @cluckinchicken, In JSON/Column formatting you need to use the Internal name of the field. Check here how to find the internal name of field in SharePoint. Mar 2 '20 at 5:32
  • @GaneshSanap Yup, I had used the internal names. Still hit or miss when it would work. Mar 2 '20 at 15:13
  • I know it's a followup, but I didn't want to post almost the exact question again, but can you add an IF to the "href" section so IF URL is empty, display the text only of [$PrimaryName], otherwise show the hyperlink? Mar 9 '20 at 20:38
2

We can use the JSON formatting below to achieve it.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "table",
    "width": "100%"
  },
  "children": [
    {
        "elmType": "a",
        "txtContent": "[$Name]",
        "attributes": {
            "target": "_blank",
            "href": "[$URL]"
        },
        "style": {
            "display": "table-cell",
            "text-align": "left",
            "vertical-align": "middle"
        }
    }
  ]
}

enter image description here

2
  • This worked as well, but I didn't see any change compared to the first answer with your additional style elements. Thanks for your answer! Feb 27 '20 at 18:35
  • If you don't add the style, the field data will not show in center.
    – LZ_MSFT
    Feb 28 '20 at 2:14

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.