1

I have a custom column formatted with JSON for SharePoint. I need all of my customization to stay, however, I do need to add the following formatting to the column:

Using boolean logic, format the link based on the filetype, prepending the Office URI Scheme to open the files in office applications based on what type of office document they are. If the files are not office files, do not prepend anything to the link and open them as is.

Example: If document is WORD (docx), prepend the Office URI Scheme of ms-word:ofe|u| to the start of the link so it forces the document to open in word, rather than save to the desktop. Here is the JSON code I need modified:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "=[$Title]",
  "attributes": {
    "target": "_self",
    "href": "=[$FileRef] + '?web=0'"
  },
  "style": {
    "text-decoration": "none",
    "color": "#000",
    "font-size": "14px"
  }
}

I asked ChatGPT, and it gave me this, however, the text doesn't display in the column:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "=[$Title]",
  "attributes": {
    "target": "_self",
    "href": {
      "operator": "+",
      "operands": [
        {
          "operator": "?:",
          "operands": [
            {
              "operator": "==",
              "operands": [
                "[$File_x0020_Type]",
                "docx"
              ]
            },
            "ms-word:ofe|u|",
            {
              "operator": "?:",
              "operands": [
                {
                  "operator": "==",
                  "operands": [
                    "[$File_x0020_Type]",
                    "pptx"
                  ]
                },
                "ms-powerpoint:ofe|u|",
                {
                  "operator": "?:",
                  "operands": [
                    {
                      "operator": "==",
                      "operands": [
                        "[$File_x0020_Type]",
                        "xlsx"
                      ]
                    },
                    "ms-excel:ofe|u|",
                    {
                      "operator": "?:",
                      "operands": [
                        {
                          "operator": "==",
                          "operands": [
                            "[$File_x0020_Type]",
                            "vsdx"
                          ]
                        },
                        "ms-visio:ofe|u|",
                        ""
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "operator": "+",
          "operands": [
            "[$FileRef]",
            "?web=0"
          ]
        }
      ]
    }
  },
  "style": {
    "text-decoration": "none",
    "color": "#000",
    "font-size": "14px"
  }
}

Thanks for any assistance you can provide!

2
  • Do you have values in [$Title] column? Also, you have to show/include Title and File Type columns in library view as you are using those in JSON. Commented Mar 15, 2023 at 3:49
  • Yup, it works until I prepend the Office URI scheme to the links. Commented Mar 15, 2023 at 16:31

1 Answer 1

0

I have tried this on our SharePoint site and found the exact same issue at our end.

I think the issue is because hyperlink URL is not starting with either http or https. Hence the hyperlink / anchor tag is not generated in DOM.

It works for other file types like PDF:

enter image description here

Similar threads:

This has been reported by other users as well in the past. check:

  1. Allow to add Office URI Schemes in SP column of type Hyperlink
  2. Allow to add Office URI Schemes in SP column of type Hyperlink
  3. Allow links using the Office URI Schemes on the navigation menu

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.