3

In SharePoint online, I need to create a list / document library with the following requirements :

  • It must have several regular columns like name, date, notes etc. (this is easy)
  • Each record must contain exactly two files (one ppt and one video file to be stored).
  • In addition to regular columns, two more columns should be there as clickable download links to these two files (say, slides and recording) - preferably as file type icons.
  • It would be better if I can add records in advance and then upload the files. (sometimes files may not be available at the moment)

I discovered the "Document Set" concept for this and think it's suitable for that. I created a content type with Document Set and then created a document library with this content type. But I couldn't achieve to do the third one. (showing download links in the list)

Any idea?
Thanks

1

In my opinion document set is the best choice here.

For the third requirement you can use JS Link to modify one of the columns.

Here is what you would need to do:

  1. Add the latest jQuery file to the Style Library.

https://jquery.com/download/

  1. Add a file with the below JavaScript to the Style Library and name it "attachmentsFieldTemplate.js":

    (function () { 
        var fieldContext = {}; 
        fieldContext.Templates = {}; 
        fieldContext.Templates.Fields = { 
            "Attachments": { "View": attachmentsFieldTemplate}
        };          
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(fieldContext); 
    })();     
    function attachmentsFieldTemplate(ctx) { 
        var id = ctx.CurrentItem.ID;
        var url = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/GetFolderByServerRelativePath(decodedurl='" + ctx.CurrentItem.FileRef + "')/Files";
        $.ajax({
            url: url,
            type: 'GET',
            headers: { 'Accept': 'application/json;odata=verbose' },
            success: function (data) {
                var links = [];
                if (data.d.results) {
                    for(var i = 0; i < data.d.results.length; i++){
                        var fileUrl = data.d.results[i].ServerRelativeUrl;
                        var fileName = data.d.results[i].Name;
                        links.push("<a href='" + fileUrl + "'>" + fileName + "</a>");
                    }
                    $("#files_" + id).html(links.join(", "));
                }
            }
        });
        return "<span id='files_" + id + "'>";
    }
    
  2. Add a new column to the library (document set) and name it "Attachments"

  3. Edit the page with the document library and edit the list Web Part
  4. In the "JS Link" field under the "Miscellaneous" section enter

    ~site/Style%20Library/jquery-3.3.1.min.js|~site/Style%20Library/attachmentsFieldTemplate.js
    

enter image description here

  1. Make sure that the "Attachments" column is added to your list view.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.