Question

I'm trying to format a SharePoint Online list using JSON. I have Title, ReportURL and Report Short Description columns. I want click on the title to go to the URL in the ReportURL column.

Using the script below it works for some links some of the time, but some links appear as javascript:void(0); in the status bar when I hover over the link. The working ones appear as a full URL in the status bar when I hover over the link.

Any idea why this is happening and how to fix it?

{
  "schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
  "hideSelection": true,
  "hideColumnHeader": true,
  "rowFormatter": {
    "elmType": "div",
    "attributes": {
      "class": "sp-row-card"
    },
    "children": [
      {
        "elmType": "div",
        "style": {
          "text-align": "left"
        },
        "children": [
          {
            "elmType": "a",
            "attributes": {
              "target": "_blank",
              "href": "[$ReportURL]"
            },
            "txtContent": "[$Title]",
            "style": {
              "color": "#0078d7",
              "font-size": "15px",
              "font-weight": "bold"
            }
          },
          {
            "elmType": "div",
            "attributes": {
              "class": "sp-row-listPadding"
            },
            "txtContent": "[$Report_x0020_Short_x0020_Descrip]"
          }
        ]
      }
    ]
  }
}
Was it helpful?

Solution

I seem to have resolved this by adding the column ReportURL to the view. I have read that columns used in the JSON formatted view have to be included in the view itself and I thought it was, but found it was not when I checked. After adding the column, the URL is successfully included in the formatted list view all the time, instead of intermittently as before.

From what I read I would have expected using the column in the JSON when it's not in the view would not return data from that column at all, so it confused me when it was returned some of the time.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top