1

Team,

I am using the SharePoint conditional formatting (bottom) to display a PDF icon in lieu of a URL link to a PDF (I run a Power Automate flow to create a PDF copy of each file uploaded to SharePoint, and I want to display an image link to the PDF copy).

The JSON below works well, except it also generates icons for sub-folders in the document library.

I need help to tweak the JSON below so that when @currentField is blank, the JSON is not run, or it suppresses the "children" properties.

If I simply place an IF statement in the SRC value, for example...

"src": "=if(@currentField = '', '', '../../SiteAssets/PDF_icon_32x32.png')"

It will display PDF icons for the files, but displays an empty image icon for the folders, rather than nothing at all.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "",
  "attributes": {
    "target": "_blank",
    "href": "[$PDFlink]"
  },
  "style": {
    "text-decoration": "none"
  },
  "children": [
    {
      "elmType": "img",
      "style": {
        "display": "block",
        "position": "relative",
        "width": "32px",
        "height": "32px"
      },
      "attributes": {
        "src": "../../SiteAssets/PDF_icon_32x32.png"
      }
    }
  ]
}

Is there a way to use the ? operator to encapsulate the children parameters into an if/then block?

1 Answer 1

1

Solved!

I found the answer here -> https://tomriha.com/hide-json-built-hyperlink-in-sharepoint-...

I changed the display value from "block" to include an if statement, so that if the @currentField is empty then display = none, else display = block.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-fo...",
  "elmType": "a",
  "txtContent": "",
  "attributes": {
    "target": "_blank",
    "href": "@currentField"
  },
  "style": {
    "text-decoration": "none"
  },
  "children": [
    {
      "elmType": "img",
      "style": {
        "display": "=if(@currentField == '','none','block')",
        "position": "relative",
        "width": "32px",
        "height": "32px"
      },
      "attributes": {
        "src": "../../SiteAssets/PDF_icon_32x32.png"
      }
    }
  ]
}

Regards Michael

Your Answer

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

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