1

I want to create a link to a document library that is automatically created by a flow.

The flow creates a file in a SharePoint document library with the following string "[Field1]-[Field2"]-'[Field3]".

The fields are column names in my SharePoint list, and the "-" are text joiners, which creates an unique file reference (reference as @currentField in Formula field).

I am trying to use the following JSON to create a row link to the document, as per the file reference:

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "a",
   "txtContent": "@currentField",
   "attributes": {
      "target": "_blank",
      "href": "='https://xxxxx.sharepoint.com/sites/xxxxx/xxxx/' + '-' 
+[$Field1] + '-' +[$Field2] + '-' +[$Field2]"
   } 
}

The main issue is I am trying to figure out how to use text joiners to replace the filepath to build a link to that document.

enter image description here

enter image description here

Updated JSON:

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "a",
    "txtContent": "@currentField",
    "attributes": {
        "target": "_blank",
        "href": "='https://xxxx.sharepoint.com/sites/SPSite/Shared%20Documents/File%20Container/' + [$OTContainer] + '-' + [$MatterCategory] + '-' + [$Title]'"
    }

Internal column name:

  1. File Reference > OTContainer
  2. Matter Category > MatterCategory
  3. Matter Name > Title
4
  • Are you trying to create a link to document library or specific document in library? What is stored in field 1, 2, 3, etc (can you add sample screenshot of your list to your question)? File name also includes -? What will be the file extension? Commented Sep 1, 2022 at 7:31
  • I have edited the original post to show the pictures. I am trying to link to a file in the document library, which is generated by referencing column names in the sharepoint list.
    – RuRon
    Commented Sep 1, 2022 at 10:24
  • It is not a "file", it's a "folder" in document library. Also, I see these folders are created inside another folder "File Container". New folders will always be created inside this folder? Commented Sep 1, 2022 at 10:29
  • Check my updated answer given below. Let me know if it helps. Commented Sep 1, 2022 at 10:32

1 Answer 1

0

Generally, the URL of document/file in library will be in format:

https://contoso.sharepoint.com/sites/SPConnect/Shared%20Documents/Document.docx

When you hit above URL in browser, browser may download it instead of opening it online in browser. So, you have to use the link like:

https://contoso.sharepoint.com/sites/SPConnect/Shared%20Documents/Document.docx?Web=1

Where, Shared%20Documents is URL name of document library and Document.docx is file name.

So, you have to use the JSON in this format:

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "a",
    "txtContent": "@currentField",
    "attributes": {
        "target": "_blank",
        "href": "='https://contoso.sharepoint.com/sites/SPConnect/Shared%20Documents/' + [$Field1] + '-' + [$Field2] + '-' + [$Field3] + '.docx?Web=1'"
    }
}

Where [$Field1] + '-' + [$Field2] + '-' + [$Field3] + '.docx should be valid file name/path.

Also, you have to use the correct internal names of columns Field1, Field2 and Field3 in JSON. You can get the internal name of your columns by following this article: How to find the Internal name of columns in SharePoint Online?

Documentation: SharePoint JSON column formatting


Update from comments:

It seems you are trying to open the folder inside document library using hyperlink. In that case, try using below JSON:

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "a",
    "txtContent": "@currentField",
    "attributes": {
        "target": "_blank",
        "href": "='https://contoso.sharepoint.com/sites/SPConnect/Shared%20Documents/File%20Container/' + [$InternalNameOfFileReference] + '-' + [$InternalNameOfMatterCategory] + '-' + [$InternalNameOfMatterName]'"
    }
}

Use correct internal names of columns in JSON.

If there is no value in a column where you are applying this JSON, use JSON like this:

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "a",
    "txtContent": "Link to folder",
    "attributes": {
        "target": "_blank",
        "href": "='https://xxxx.sharepoint.com/sites/SPSite/Shared%20Documents/File%20Container/' + [$OTContainer] + '-' + [$MatterCategory] + '-' + [$Title]'"
    }
}
6
  • Thank you for your link, I have used this to find the internal names of the columns and modified the code. For some reason, the calculated column in the List is not displaying a link.
    – RuRon
    Commented Sep 2, 2022 at 1:57
  • Can you add the JSON code you are using currently to your question? You can edit original question and add the JSON. Commented Sep 2, 2022 at 3:12
  • Updated the original question with the JSON code used.
    – RuRon
    Commented Sep 2, 2022 at 4:44
  • Is there any value in column where you are applying this JSON? If not, use txtContent in JSON like: "txtContent": "Link to folder",. Check updated answer for full JSON. Commented Sep 2, 2022 at 4:49
  • There is no value in the column, as the column is new. I have used the updated JSON, but no Link to Folder text is visible.
    – RuRon
    Commented Sep 3, 2022 at 14:40

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.