Introduction

In this blog, I would like to explain how to create Document Set In Document Library, using JSOM. A Document Set is a group of related documents, which can be created in one step and then managed as a single entity.

Source Code

  1. $(document).ready(function() {
  2. createDocumentSet();
  3. });
  4. functioncreateDocumentSet() {
  5. varclientContext = new SP.ClientContext.get_current();
  6. oWeb = clientContext.get_web();
  7. varoList = oWeb.get_lists().getByTitle("TestLibrary");
  8. clientContext.load(oList);
  9. varLibraryFolder = oList.get_rootFolder();
  10. clientContext.load(LibraryFolder);
  11. vardocumentSetContentTypeID = "0x0120D520";
  12. vardocumentSetContentType = clientContext.get_site().get_rootWeb().get_contentTypes().getById(documentSetContentTypeID);
  13. clientContext.load(documentSetContentType);
  14. clientContext.executeQueryAsync(QuerySuccess, QueryFailure);
  15. }
  16. functionQuerySuccess() {
  17. vardocumentSetName = "DocumentSetName";
  18. SP.DocumentSet.DocumentSet.create(clientContext, oLibraryFolder, documentSetName, documentSetContentType.get_id());
  19. clientContext.executeQueryAsync(Success, Failure);
  20. }
  21. functionQueryFailure() {
  22. console.log('Request failed - ' + args.get_message());
  23. }
  24. function Success() {
  25. console.log('DocumentSet Created Successfully.');
  26. }
  27. function Failure(sender, args) {
  28. console.log('Request failed - ' + args.get_message());
  29. }
Activate Document Set Feature

We need to activate it before you can create or configure new Document Set content types.

Add Document Set as a Content Type to your Document Library,

Here, we will see how to create a Document Set programatically, using Jsom.