0
votes

On my Sharepoint online site I have a document library that contains document sets. The document sets allow a custom document type (inherited from document). In some cases I display the documents as a flat list (i.e. output includes documents from multiple document sets). In these instances I would like the user to be able to navigate to the document set that contains the document.

For example: Document A is in Document Set 123 and document B is in Document Set 456. I have a view that shows both A and B. When the user looks at the details of A, there will be a link to 123. Similarly, when the user look at the details of B, there will be a link to 456.

I'd prefer an OOTB solution.

Thanks!

2

2 Answers

0
votes

Per my knowledge, there is not an OOTB way to achieve it. As a workaround, we can add custom code below into script editor web part in DispForm.aspx page to achieve it.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
    var rootFolder=getUrlParameter("RootFolder");
    $("#documentset").append("<a href='"+rootFolder+"' target='_blank'>Link to Document Set</a>");
});
function getUrlParameter(name) {
    name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
    var results = regex.exec(decodeURIComponent(location.search));
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}
</script>
<div id="documentset"/>

enter image description here

0
votes

Thanks for this.

Here is the solution I came up with. Assume we are working with a content type called ct1 that inherits from documentSet and that document set

  1. Create a document set content type that inherits from document set. For the purposes of this solution, we'll call it School.
  2. Create a string field in School, we'll call it schoolName
  3. Either manually or via workflow set schoolName = the name field of school
  4. Create a content type of Student that inherits from Document
  5. Add Student to the School Content Type
  6. In the School content type Document Set Settings page make sure that schoolName is checked in the shared columns section
  7. Create a document library (Schools) and add school content type
  8. In schools add a new school
  9. Open the new school and copy the url and paste it in a text editor
  10. Remove the school name from the end of the URL
  11. In the Student content type add a computed column (i.e. link to school)
  12. Set the formula to =schoolName
  13. Following the example at (https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting#create-clickable-actions) set the column formatting to:

{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "a", "txtContent": "@currentField", "attributes": { "target": "_self", "href": "='[URL copied from clipboard]' + @currentField" } }

where [URL copied from clipboard] is the URL from step 9 (without the school name at the end)

You should now be able to add the calculated column to any view and it will link back to the parent folder