SharePoint Online Document Library - JSON Column Formatting Not Opening O365 Docs in Browser Application

Schneider, Kelly (DEED) 1 Reputation point
2021-07-08T16:41:36.29+00:00

I have a document library in SPO where I've used JSON column formatting to display the Name (filename) field as the Title, and clicking opens the document. The JSON has a target of _blank, so docs open in a new tab. PDF files have the expected behavior of opening in a new tab in the browser. O365 documents open a new tab and then the user gets prompted to open in the Client Application. The library is set to "open in browser" as default. "Open in Client Application" is not turned on at the site collection level.

When I look at the "get link" for a document in SPO, it's always link plus a bunch of stuff, and I assume the rest of that stuff is what opens the doc in the web browser. Is there a way to do this programmatically with JSON? Clarification: I want the documents to open in the browser, NOT the client application. I'm getting the opposite result with the JSON below.

For reference, the JSON I'm using is nearly identical to what was posted in this question as a workaround to force opening in the client application: https://answers.microsoft.com/en-us/msoffice/forum/all/sharepoint-online-document-library-not-opening-in/6012959a-d5e5-4e64-8ac0-5cb153317fe4

My code is:

{

"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",

"elmType": "a",

"txtContent": "[$Title]",

"attributes": {

"target": "_blank",

"href": "='[DOCUMENT LIBRARY LINK]' + @currentField"

}

}

I can't find anything in the "Use column formatting to customize SharePoint" article that's specific to how SharePoint opens O365 documents: https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting

Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Allen Xu_MSFT 13,861 Reputation points
    2021-07-09T07:10:32.337+00:00

    Hi @Schneider, Kelly (DEED) ,

    Is Title field a single line of text column created by yourself in SharePoint Online? If we apply no JSON forammting code and enable "open in browser" as default in Library settings, the document can be opened in a new tab and in browser office online when clicking a document name in OOTB Name field. I'm confused why you need a new field instead of an OOTB one.

    The way which decides where the the dcoument to be opened in is decided by the URL. The 'href' tag in your code redirects the documents to be opened in client app. You can have a try to directly paste the "'[DOCUMENT LIBRARY LINK]' + @currentField" URL into your browser and you will find that the document will be opened in client app. Also, you can have a try click the document name in the OOTB Name field and pay attention to what the URL is when opened in browser. You will find that the URL is like this: https://<tenantname>.sharepoint.com/:w:/r/sites/<sitename>/_layouts/15/Doc.aspx?sourcedoc=<documentid>&file=<documentname>&action=default&mobileredirect=true. That's why the document is opened in diffreent ways. As per my knowledge, we have no way to dinamically get document id and document name using front end JSON formatting code.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Ganesh Sanap 211 Reputation points
    2022-09-05T06:29:07.257+00:00

    Try using href in JSON like:

    "href": "='[DOCUMENT LIBRARY LINK]' + @currentField + '?Web=1'"

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.