Document sets are part of a site collection feature.

Let’s try to retrieve all the documents from a document set using JavaScript Object Model.

- <script language="javascript" type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
- <script language="javascript" type="text/javascript">
- $(document).ready(function() {
- var scriptbase = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/";
- $.getScript(scriptbase + "SP.Runtime.js", function() {
- $.getScript(scriptbase + "SP.js", function() {
- $.getScript(scriptbase + "SP.DocumentManagement.js", createDocumentSet);
- });
- });
- });
- var docSetFiles;
- function createDocumentSet() {
- //Get the client context,web and library object.
- clientContext = new SP.ClientContext.get_current();
- oWeb = clientContext.get_web();
- var oList = oWeb.get_lists().getByTitle("Demo Library");
- clientContext.load(oList);
- //Get the root folder of the library
- oLibraryFolder = oList.get_rootFolder();
- var documentSetFolder = "/sites/Playground/Demo%20Library/Long Term Execution
- Planning ";
- //Get the document set files using CAML query
- var camlQuery = SP.CamlQuery.createAllItemsQuery();
- camlQuery.set_folderServerRelativeUrl(documentSetFolder);
- docSetFiles = oList.getItems(camlQuery);
- //Load the client context and execute the batch
- clientContext.load(docSetFiles, 'Include(File)');
- clientContext.executeQueryAsync(QuerySuccess, QueryFailure);
- }
- function QuerySuccess() {
- //Loop through the document set files and get the display name
- var docSetFilesdocSetFilesEnumerator = docSetFiles.getEnumerator();
- while (docSetFilesEnumerator.moveNext()) {
- var oDoc = docSetFilesEnumerator.get_current().get_file();
- console.log("Document Name : " + oDoc.get_name());
- }
- }
- function QueryFailure() {
- console.log('Request failed - ' + args.get_message());
- }
- </script>

Summary
Thus, we saw how to retrieve the documents from a Document Set in SharePoint 2016, using JavaScript Object Model.

Jason Clark (Mbcs)Posted Nov 1, 2018, 9:33 AM
Hi, this code is not robust. It will break as soon as a power user or site admin changes the name of the document set or library. You need to account for ALL eventualities in your testing and assume nothing.
darren muscatPosted Sep 27, 2018, 5:31 AM
Hi, noticed a small typo in line 34 var docSetFilesdocSetFilesEnumerator , should be var docSetFilesSetFilesEnumerator .