question

SchneiderKellyDEED-3582 avatar image
0 Votes"
SchneiderKellyDEED-3582 asked AllenXu-MSFT commented

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

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://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting

office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AllenXu-MSFT avatar image
0 Votes"
AllenXu-MSFT answered AllenXu-MSFT commented

Hi @SchneiderKellyDEED-3582 ,

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@SchneiderKellyDEED-3582,

I'm checking how things are going on this thread. Please feel free to let me know if there is any update.

0 Votes 0 ·

@SchneiderKellyDEED-3582,

Is there any progress on this thread? I'm waiting for your responese :-)


If an Answer is helpful, please click "Accept Answer" and upvote it.

0 Votes 0 ·