1

I have a SharePoint Online list and a document library. Within the list, there is a Lesson Name column (Title is internal name). I'm trying to add a column (to the list) that includes a link to the document library that only populates the documents associated with the lesson name of the list item.

I've created a calculated column and used the below JSON in the column formatting box. A link is created and takes me to the document library BUT it includes, what seems to be random results. What am I doing wrong?

I'm also open to any other suggestions on the best way to create a link to the filtered library. I've tried a Power Automate flow in the past and have had multiple issues that I've been unable to resolve. I've also considered a lookup column as that has been suggested quite a bit but I can't wrap my head around how that will work. So hoping for some help here from you lovely people!

{ 
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "a", 
"txtContent": "= 'Materials for ' + [$Title]", 
"attributes": { 
  "href": "= @currentWeb + '/Part%20C%20Materials/Forms/AllItems.aspx?view=7&q=' + [$Title]", 
   "target": "_blank" 
 } 
}
1
  • You want to search based on title in the list or you have any column in the document library which has exact values similar to the list item titles? Jun 21, 2023 at 3:58

1 Answer 1

1

By looking at the JSON you provided, you are searching the document library based on the Title column in the SharePoint list, similar to my answer given at: Filter a document library from a list

And I believe those will not be the random results. Document library will search the documents based on query text for below conditions:

  1. Document/file name contains the query text
  2. Document/file content contains the query text

Example:

enter image description here

Where "HR Yearly Goals Sheet.docx" document has this content:

enter image description here


If you have any column in the document library which has exact values similar to the list item titles, you can also do the filtering based on exact column match like (example based on filtering choice column in the document library):

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "= 'Materials for ' + [$Title]",
  "attributes": {
    "href": "= @currentWeb + '/Part%20C%20Materials/Forms/AllItems.aspx?FilterField1=ChoiceCol&FilterType1=Choice&FilterValue1=' + [$Title]",
    "target": "_blank"
  }
}

Where ChoiceCol is the internal name of the choice column in the document library. You can get the internal name of your columns by following this article: How to find the Internal name of columns in SharePoint Online?

Output (filtered document library):

enter image description here

Similar thread: How to filter SharePoint list using url parameters- SPO Modern UI

2
  • 1
    HI Ganesh! I understand what you mean now by not random as it is based on the document name AND/OR content. Makes perfect sense so thank you for pointing that out. I used the second piece related to the using the document library ChoiceCol. This works exactly as I need it. Thank you so much for your help! I truly appreciate it! Jun 21, 2023 at 18:29
  • Great, glad it helped you. Jun 22, 2023 at 5:56

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.